i need to create multiple javascript functions which have a static id inside, so the function itself knows what data to process.
Here is some code:
(function(){
function log(s){
if(console && console.log) console.log(s);
else alert(s);
}
var i = 10; while (i--){
window.setTimeout(function(){
// i need i to be 10, 9, 8... here not -1
log(i);
},500);
}
})();
The problem ist that i allways gets updated by the loop, and i need to prevent this.
Thanks in advance for any help, comments or tips!
Just create a function and call it.
while (i--) {
(function(i) {
// use i here
})(i);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With