所以,我一直在看这篇文章:What is the purpose of Node.js module.exports and how do you use it?并一直在努力使JavaScript对象的范围之内它的意义。对象对象
所以,如果我有这样的game.js
:
var myObj = function() {
this.function1 = function(){
...
};
};
exports.myObj = myObj;
在我假设我会做这样的事情的其他文件:
var RequiredObj = require('game.js');
或
var RequiredObj = require('game.js').myObj;
我迷失方向的是如何使用此对象及其功能,以及如何创建此ob的新实例JECT。
会是这样的吗?
RequiredObj.myObj.function1();
和
RequiredObj.myObj = new RequiredObj.myObj();
也没有任何限制,我传递对象有多大?因为在我的实际脚本中,我的游戏对象非常庞大。
谢谢。这是非常彻底的。 –