我可以建立一个导出实例化变量的模块吗?实例化事物的节点模块?
模块:
var module1 = require('module1')
var Module2 = require('module2')
module1.dosomething(variables)
exports.module1 = module1
//or
module2 = new Modle2(variables)
module2.dosomething(variables)
exports.module2 = module2
我可以要求模块上方在许多其他文件,并使用出口作为实例变量或将它们重新实例每次我需要他们,并要求他们在文件之间不共享时间。
谢谢!
您可以执行。不是一个好的答案。这取决于你想怎么做。 –
我可以做这些和出口都不会被重新实例化模块1和模块2的versons每次需要?导出将始终引用已经实例化的版本? – fancy
这取决于,但是,看到我对这个问题的答案http://stackoverflow.com/questions/8931239/how-to-access-variables-declared-in-main-app-js-in-seperate-route- files-in-node/8931366#8931366 –