2013-08-23 57 views
0

如何通过另一个模块导出一个模块的所有功能。像下面的伪代码:将所有功能从一个模块转移到另一个模块 - node.js

模块one.js

exports.func1 = ... 
exports.func2 = ... 
exports.func2 = ... 

模块two.js

one = require 'one.js' 

exports = exportallfrom(one) 

模块three.js所

two = require 'two.js' 

two.func1() 
two.func2() 
two.func3() 
+0

'出口= one'? – soulcheck

回答

1

您可以two继承one,使用Object.create()建立原型c它们之间海恩:

module.exports = exports = Object.create require './one.js' 

# ... 

或者,你可以简单地遍历oneproperties,复制他们的价值观:

one = require './one.js' 
Object.keys(one).forEach (key) -> 
    exports[key] = one[key] 

# ... 
相关问题