【发布时间】:2016-12-20 15:33:39
【问题描述】:
我创建了一个非常简单的模块来测试这项工作的可行性。这里是SPServerApp.ts的开头:
class SPServerApp {
public AllUsersDict: any;
public AllRoomsDict: any;
constructor () {
this.AllUsersDict = {};
this.AllRoomsDict = {};
}
}
module.exports = SPServerApp();
然后在我的应用程序中,我有这个要求声明:
var serverapp = require('./SPServerApp');
然后我尝试像这样访问其中一个字典:
serverapp.AllUsersDict.hasOwnProperty(nickname)
但得到错误:
TypeError: Cannot read property 'hasOwnProperty' of undefined
谁能看到我在这里做错了什么?
谢谢,E。
【问题讨论】:
-
你没有实例化这个类。添加“新”或在您需要的地方创建一个新实例。
-
确实有效。谢谢菲克斯。
-
我认为这个链接会对你有所帮助。 stackoverflow.com/questions/23739044/…
标签: node.js node-modules typescript1.8