如何通过另一个模块导出一个模块的所有功能。类似于下面的伪代码:
模块一.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()
如何通过另一个模块导出一个模块的所有功能。类似于下面的伪代码:
模块一.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()
您可以two
继承 from one
,Object.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]
# ...