client.on('message', function(obj){});
This works fine, but I am trying to avoid nesting, so I take the callback function out like so:
client.on('message', doThis(obj));
function doThis(obj) {}
But this gives me an error saying obj is undefined.
How do I pass the message data to the callback function?
Thanks
f(doThis)is the correct syntax.f(doThis(arg))is the wrong syntax.The latter is calling
doThisimmediately with the argumentarg(which doesn’t exist yet).That’s why it says
objis undefined because your callingdoThisimmediatly.What
f(doThis)does is passes the function on instead of the return value of the function