Created
March 7, 2014 00:49
-
-
Save d-simon/9402916 to your computer and use it in GitHub Desktop.
For-Loop / Pass iterator into async callback
This file contains 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
for (var i = 0; i < array.length; i++) (function (i, arrayElement) { | |
// this will create a new variables i and arrayElement for each loop iteration | |
// so we can use it in an async callback | |
doSomeAsync(function callback () { | |
console.log(i, arrayElement); | |
}); | |
}) (i, array[i]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment