node.js需要继承吗?
问题描述:
在我的server.js中我包含了下划线库。
in my server.js i included the underscore library.
var _ = require('underscore')
我有这样的路线:
// require routes
require('./routes/document');
在文档路径中,我想使用下划线。但似乎_ var不是继承/在文档范围内。这是否意味着我必须在每个必需的路线上设置_ var?或者有更智能的方法吗?
In the document route, I want to use underscore. But it seems like the _ var is not inherited/in side the document scope. Does that mean I have to set the _ var on every single required route? Or is there a more intelligent way to do this?
谢谢。
答
是的,你应该在需要它的文件中设置_。
Yes, you should set the _ in the files that needs it to be available.
或者,你可以通过删除 var part。
Alternatively, you can put it in the global scope by removing the var
part.
_ = require('underscore');
require('./routes/document'); // _ will be visible in document as well