Node.js全局变量 [英] Node.js global variables
本文介绍了Node.js全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里问: > Node.js是否需要继承?
I asked here: Does Node.js require inheritance?
有人告诉我,可以通过省略变量来将变量设置为全局范围.
And I was told that I can set variables to the global scope by leaving out the variable.
这对我不起作用.
也就是说,以下内容不能使_
在所需文件上可用.
That is, the following does not make the _
available on required files.
_ = require('underscore');
我可以使用Express.js的app.set
进行设置,并使其在其他位置可用.
I can set with Express.js's app.set
and have it available elsewhere though.
这应该是如何工作的吗?
Is that how this is supposed to work?
推荐答案
您可以使用 global
像这样:
You can use global
like so:
global._ = require('underscore')
这篇关于Node.js全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文