Every single JavaScript engine supports standard timers *
These accept one or more extra argument by specs
for(var i = 0; i < 2; i++) {
setTimeout(function (i) {
console.log(i);
}, 0, i); // <== see this?
}
You don't need an inline invoked function, you don't need to bind arguments, you just pass one or more parameter once and you are done.
- JScript (IE8 and lower) and IE9 are the only exception, all others since ever supports extra arguments, including IE10, 11, and Sparta. IE9 and 8 or lower browsers are very easy to fix in a completely unobtrusive way.
Using
i
in the inner function seems confusing, would it be better as something like this?