Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Forked from anonymous/gist:2836165
Created May 30, 2012 13:03
Show Gist options
  • Save hughfdjackson/2836182 to your computer and use it in GitHub Desktop.
Save hughfdjackson/2836182 to your computer and use it in GitHub Desktop.
for (var i = 0; i < 10; i++) {
process.nextTick(function (i) { console.log(i); }.bind(this, i));
}
// Prints 10 x 10 times
// I want it to print 1 - 10 without using an external array to store i
/*
In browser test edition
var process = {}
process.nextTick = function(fn){
setTimeout(fn, 1)
}
for (var i = 0; i < 10; i++) {
process.nextTick(function (i) { console.log(i); }.bind(this, i));
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment