Rexport all features from one module to another - node.js

How to export all features of one module via another. Something like in the pseudocode below:

Module one.js

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

Module two.js

 one = require 'one.js'

 exports = exportallfrom(one)

Module three.js

two = require 'two.js'

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

Answers


You can have two inherit from one, using Object.create() to establish a prototype chain between them:

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

# ...

Or, you can simply iterate over one's properties, copying their values:

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

# ...

Need Your Help

For any string “char name=”test“”,is strlen(name)+1 always guaranteed to be same as sizeof(name)?

c sizeof strlen size-t

For a string name[],can we use strlen(name)+1 and sizeof(name) interchangeably in our code without second thought?Aren't they same?I checked about it and found out even the return type for both is

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.