When I execute the following, incidentController
gets called after 10
seconds and continues to execute with no problems every 10
seconds:
// This works fine in nodejs v0.11.13
setInterval(incidentController, 10 * 1000);
function incidentController () {
console.log ('executed');
}
However, this executes immediately and throws the following error on the second iteration:
//This doesn't. The parens which wrap (123) cause the error.
setInterval(incidentController(123), 10 * 1000);
function incidentController (someInt) {
console.log ('executed: ', someInt);
}
Error:
timers.js:287
callback.apply(this, args);
^
TypeError: Cannot read property 'apply' of undefined
at wrapper [as _onTimeout] (timers.js:287:13)
at Timer.listOnTimeout (timers.js:133:15)
It seems like incidentController
is/becomes undefined
somehow. Can someone explain why this is expected behavior (I assume it is, anyway)?
I can work around this pretty easily, but I'm just curious why it behaves this way -- makes passing in parameter values a bit less convenient since I can't do it inside the setInterval
statement itself.