Possible Duplicate:
setTimeout in a for-loop and pass i as value
for (var i = 0; i < 5; i++) {
setTimeout(function (i) {
console.log(this.i)
}, 1000);
}
This prints 5
five times. How can I write the loop so that it prints 0, 1, 2, 3, 4
?