在node.js中构build可扩展的可链接模块

我想build立一个node.js模块,我可以扩展我的模块加载(如jQuery插件),并具有这些插件的function可链接。

据我所知,如果我从模块中返回一个更新的对象,它们应该是可链接的。 (我从这里得到了http://javascriptissexy.com/beautiful-javascript-easily-create-chainable-cascading-methods-for-expressiveness/ )

到目前为止,这是我所拥有的,而且我不确定完全出错的地方。

我build立我的对象

var my_obj = new MyObj(json_obj); var modules = ['get_and_set']; // an array for plugins to be included MyObj.prototype.core_function = function(){ // does something and returns } if(modules){ modules.forEach(function(module){ MyObj.prototype = require(module); }); } // then I export my module module.exports = my_obj(json_file); 

然后,在我的孩子模块,我导出命令function,我试图添加到我的模块。

 module.exports.get = function(){ return this.value; } module.exports.set = function(x){ this.value=x; return this; } 

当我运行我的testing时,节点吐出错误说has no method gethas no method set

有没有更好的方式来扩展MyObj,而无需手动定义从导出的模块中包含哪些方法? 我在做链接吗?