Javascript: how to pass parameters to callback function

Viewed 9510

I'm stumped on how to correctly pass parameters to a callback function without immediately calling that function.

For example, this will work as expected:

var callBack = function() { ... }
window.setTimeout( callBack, 1000 );

But this will accidentally call callBack:

var callBack = function(param1, param2) { ... }
window.setTimeout( callBack('foo','bar'), 1000 );
2 Answers
Related