【发布时间】:2018-05-21 21:17:56
【问题描述】:
文件名:orderManager.js
const notificationManager = require("./notificationManager");
var orderManager = (function() {
function orderManager() {
console.log("orderManager");
};
orderManager.bootstrap = function() {
console.log("orderManager.bootstrap");
return new orderManager();
};
orderManager.prototype.orderContext = {
"CONTEXT_1": "context_1",
"CONTEXT_2": "context_2",
"CONTEXT_3": "context_3"
};
orderManager.prototype.notify = function() {
var dataObj = {};
notificationManager.sendToClient(dataObj);
};
return orderManager;
}());
module.exports = orderManager.bootstrap();
文件名:notificationManager.js
const orderManager = require("./orderManager");
var notificationManager = (function() {
function notificationManager() {
console.log("notificationManager");
};
notificationManager.bootstrap = function() {
console.log("notificationManager.bootstrap");
return new notificationManager();
};
notificationManager.prototype.sendToClient = function(dataObj) {
console.log("notificationManager.prototype.sendToClient");
var _this = this;
switch (_this.request.body.orderContext) {
case orderManager.orderContext.CONTEXT_1:
notifyClient(_this, dataObj);
break;
}
};
return notificationManager;
}());
module.exports = notificationManager.bootstrap();
当我尝试从 orderManager.js 文件中调用 notificationManager.sendToClient() 函数时,会出现错误 TypeError: Cannot read property 'CONTEXT_1'的未定义。
【问题讨论】:
标签: node.js