Created
April 27, 2012 17:36
-
-
Save chrisinajar/2511098 to your computer and use it in GitHub Desktop.
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
var doStuff = function(val, cb) { | |
// Call the callback later! | |
setTimeout(function() { cb(val); }, 1); | |
} | |
var total = 5; | |
for (var i = 0, c = 0; i < total; ++i) { | |
doStuff(i, function(val) { | |
console.log('Got a return value! ' + val); | |
if (++c === total) { | |
console.log('All 5 are done'); | |
} | |
}); | |
} | |
console.log('This debug statement will appear first! Weird, huh...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment