0

如何通过另一个模块导出一个模块的所有功能。类似于下面的伪代码:

模块一.js

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

模块二.js

 one = require 'one.js'

 exports = exportallfrom(one)

模块三.js

two = require 'two.js'

two.func1()
two.func2()
two.func3()
4

1 回答 1

1

您可以two继承 from oneObject.create()用于在它们之间建立原型链:

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

# ...

或者,您可以简单地迭代one's properties,复制它们的值:

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

# ...
于 2013-08-23T10:57:41.600 回答