-2
我有一个变量,我想要在模块之间共享并添加到它,从中删除并在Node.js程序中修改它是我所做的:Node.js:模块之间通过module.exports共享变量
shared_storage.js
var locations = {};
locations['Brandenburg Gate'] = {latitude: 52.516272, longitude: 13.377722};
locations['Dortmund U-Tower'] = {latitude: 51.515, longitude: 7.453619};
module.exports = locations;
var state = new Object(); // Create the object
state.ready = "r";
state.offline = "o";
state.loaded = "l";
var location_stats = {};
location_stats ['Brandenburg Gate'] = state.ready;
location_stats ['Dortmund U-Tower'] = state.loaded;
module.exports = location_stats ;
mymodule.js
var spots= require('./shared_storage').locations;
console.log(spots);
但结果是:
不确定
哪里是我添加到变量在shared_storage.js
项目吗?
可以请您发布完整的shared_storage.js吗?你是否创建了构造函数?如果是的话,你有导出构造函数。 – Subburaj