Created
September 7, 2011 19:16
-
-
Save user24/1201439 to your computer and use it in GitHub Desktop.
Async Loop Pitfall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the following code outputs: 999999999 | |
var someArray = [1,2,3,4,5,6,7,8,9]; | |
for(var i=0 ; i<someArray.length ; i++) { | |
performSomeAsyncOperation("foo", function hereIsACallback() { | |
console.log(someArray[i]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One way to avoid this: