I have a loop, a setTimout and a callback. I need to use an anonymous function to keep the variables correct in the callback.
I want to have the callback as a separate function because it is too large to have in the loop.
This does not work:
for (var i = 0; i < 10; i++) {
setTimeout(callback, 1000*i, i);
}
var callback;
(callback = function(i) {
console.log(i);
})();
How can define an anonymous function that I can call from setTimeout?