Node.Js + Expressjs中的inheritance

我正在尝试在Node.js和Express.js中实现类似以下内容的function,但无法find有效的示例。 帮助赞赏。

base.js -------- module.exports = { baseFunction: function(){ ..... } } child.js -------- module.exports = { require('base'), ***** Some Magical Code ****** childFunction: function(){ ..... } } CallProgram.js -------------- var child = require('child'); child.baseFunction(); 

这个怎么样?

 function extend(a, b) { var result = Object.create(a); for (var prop in b) { if (b.hasOwnProperty(prop)) { result[prop] = b[prop]; } } return result; } module.exports = extend(require('base'), { ***** Some Magical Code ****** childFunction: function(){ ..... } }); 

扩展函数将创build一个新的对象作为其原型,并将复制到其上的所有属性。