This, will log ‘7’ seven times after 1 second.
for (var i = 0; i < 7; i++) {
$.doTimeout(1000, function() {
console.log(i);
});
}
But how to do if I want it to log ‘0’,’1′,’2′,’3′,’4′,’5′,’6′ ?
($.doTimeout is the Ben Alman’s plug-in, but I think it’s the same problem with setTimeout.)
Thanks!
You need to associate a scope to the variable
iso that when the closure looks it up it gets the value from that scope.