Let's say I have something like this:
for(var i = 0; i < length; i++){ var variable = variables[i]; otherVariable.doSomething(variable, function(err){
By the time the callbacks are called, variable will inevitably be the last variable for all callbacks, instead of being different for each callback as I would like. I understand that I could pass variable to doSomething() and then pass this as part of the callback, but doSomething() is part of an external library, and I would prefer not to interfere with the source code for this.
Do you have anyone who knows JavaScript better than I know, are there alternative ways to do what I would like to do?
Best and thanks
Themselves
javascript callback
thisissami Aug 13 '11 at 23:32 2011-08-13 23:32
source share