I am writing a node.js module that exports two functions and I want to call one function from the other but I see an undefined reference error.
Is there a pattern to do this? Do I just make a private function and wrap it?
Here's some example code:
(function() {
"use strict";
module.exports = function (params) {
return {
funcA: function() {
console.log('funcA');
},
funcB: function() {
funcA(); // ReferenceError: funcA is not defined
}
}
}
}());
I like this way:
(function() {
"use strict";
module.exports = function (params) {
var methods = {};
methods.funcA = function() {
console.log('funcA');
};
methods.funcB = function() {
methods.funcA();
};
return methods;
};
}());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With