Reputation: 299
I'm trying to rewrite my socket.io server in order to dodge the "callback hell" thing. Now I'm trying to listen for an event, and instead of passing an anonymus function as callback, I want to pass a function exported by a module.
Basically I want to do this
socket.on('joinChat', myFuncExportedByModule(/* stuff */));
Instead of this
socket.on('joinChat', function() {
/* stuff */
});
As soon as I tried to invoke myFuncExportedByModule, node sent me back an "TypeError: listener must be a function".
Any ideas?
Upvotes: 2
Views: 1186
Reputation: 106
I think the error is you're not passing a function, but executing it.
Try remove parenthesis:
socket.on('joinChat', myFuncExportedByModule);
Upvotes: 4