Is there a way to do the following without creating an anonymous function 10 times? Assuming setTimeout only takes 2 parameters, the callback and the interval. From what I've heard you shouldn't create functions in a loop since it's slow. However, if an asynchronous function doesn't allow you to pass it the parameters you want the callback to know about, is it possible to avoid doing so? Note: I know in Chrome setTimeout takes more params, so this isn't an ideal example.
function doSomethingAsync(i){
setTimeout(function() { //This anonymous function is created 10 times
console.log(i);
}, 1000);
}
for (var i = 0; i < 10; i++) {
doSomethingAsync(i);
}