Tag: 常量

如何在Grunt中执行属性预处理?

Grunt具有用于在执行任务之前设置和更新configuration属性的语法。 例如, config { dist: { dir: "dir1" }, clean: { dirs: [ '<dist.dir>' ] } } 成为记忆中的… config { dist: { dir: "dir1" }, clean: { dirs: [ "dir1" ] } } npm模块负责这个? 请告诉我如何以更好的方式实现它? 谢谢!

将库声明为常量

在NodeJS世界中,我们需要使用require函数的模块: var foo = require ("foo"); 在JavaScript中(也在NodeJS中),我们有const关键字创build一个常量: const 创build一个常量,该常量可以是声明它的函数的全局或局部的。 常量遵循与variables相同的范围规则。 例: $ node > const a = 10 undefined > a 10 > a = 7 7 > a 10 我的问题是:将库作为常量是否会很好? 例: const foo = require ("foo") , http = require ("http") ; /* do something with foo and http */ 使用const而不是var时有什么不好/很好的效果,当需要库?

NodeJs定义全局常量

即时通讯想知道如何在节点js中定义全局常量。 我的方法到目前为止: constants.js: module.exports = Object.freeze({ MY_CONST: 'const one'}); controller.js: var const = require(./common/constants/constants.js); console.log(const.MY_CONST) ==> const one const.MY_CONST ='something' console.log(const.MY_CONST) ==> const one 那好吧到目前为止。 但是,我想这样构造我的常量: constants.js: module.exports = Object.freeze({ MY_TOPIC: { MY_CONST: 'const one' } }); controller.js: var const = require(./common/constants/constants.js); console.log(const.MY_TOPIC.MY_CONST) ==> const one const.MY_TOPIC.MY_CONST ='something' console.log(const.MY_TOPIC.MY_CONST) ==> something 嗯,没有MY_CONST不是不变的…我怎样才能解决这个问题?

为什么Node.js中的事件不是常量?

我是新来的节点,但我来自广泛的编程背景。 我看到的每一个地方(无论是在教程还是在我看到的产品代码中),人们绝大多数使用硬编码的string而不是常量来识别事件。 我从npm 最依赖于软件包列表中select了一个随机的例子来说明我的意思: “请求”库 – 为什么他们每次都inputstring'data'来发出和使用 «data»事件,而不是定义图书馆的常量? 在我意识到的任何编程语言中,使用常量都被认为是一个好习惯,然而节点开发人员似乎完全满足于硬编码的方法。 为什么?