I was wondering if the following code could introduce race conditions:
rows.each(function () {
var current = this;
var doOperation = function () {
current.someMethod();
// do some operation using current
};
setTimeout(doOperation, 1);
});
During the settimeout delay, is it possible that the browser will start executing the next itteration of the loop and change “current”, so that doOperation doesn’t exuecute using the value that was orignally assigned?
There’s no danger there, because each iteration’s
doOperationwill close over a newcurrentlocal variable, not interfering with previous ones.