samedi 28 février 2015

How to export inter-depended Node.js functions efficiently

I have a Node.js module containing numerous functions:


myfuncs.js:



var foo = function(d) { return d + 1 })
var bar = function(d) { return foo(d) + 2 }
var baz = function(d) { return foo(d) + bar(d) + 3 })


I'd like to export all of these function in myfuncs.js for use in another module. What is the best way to accomplish this? Since some of the functions are used in other functions; for example foo is used in bar and baz, the only way I can see to export, is to list all the exports like this, so that they are available in another module.


myfuncs.js:



var foo = function(d) { return d + 1 })
var bar = function(d) { return foo(d) + 2 }
var baz = function(d) { return foo(d) + bar(d) + 3 })

module.exports.foo = foo;
module.exports.bar = bar;
module.exports.baz = baz;


My issue is that I have dozens of functions and exporting each function in this manner seems inefficient. Is there a better way to export Node functions?


Aucun commentaire:

Enregistrer un commentaire