my question is actually one of understanding - I have a working solution, I just don’t understand how it works.
Well, therefore, what I'm trying to do is add setTimeout in a loop and pass a variable value through it. Example:
for (i=0;i<11;i++)
{
setTimeout("alert(i)",1000);
}
If I understood correctly, this does not work, because Javascript does not pass (like PHP) the value I to the function, but passes the link I - which, in turn, is not static, but continues to change using a counter.
I found a solution that looks like this:
for (i=0;i<11;i++)
{
setTimeout(function(x){return function(){alert(x)};}(i),1000);
}
I really don’t understand what it really is. It looks like it is returning the alert function back to the calling function, but I cannot interpret this.
, , , , -, , . , .
,