I'm dealing with the closure issue right now and I need a little help on the topic: Using this code for my training:
for (var i = 1; i <= 10; i++) {
setTimeout(function(j) {
console.log(j);
}(i), 1000);
}
This solution timeouts for a second and then prints 1-10 in ascending order (as expected). Now, I want it to print j once every second:
1 (second passed...)
2 (second passed...)
3 (second passed...)
etc..
How can I make this happen without changing the formation of the loop?
Thanks in advance