Node JS - Calling a method from another method in same file
You can do it this way:
module.exports = {
foo: function(req, res){
bar();
},
bar: bar
}
function bar() {
...
}
No closure is needed.
The accepted response is wrong, you need to call the bar method from the current scope using the "this" keyword:
module.exports = {
foo: function(req, res){
this.bar();
},
bar: function() { console.log('bar'); }
}
I think what you can do is bind the context before passing the callback.
something.registerCallback(module.exports.foo.bind(module.exports));