+ 2
In the following code why doesn't first and second block moves ,am i missing something? [SOLVED]
So I thought i did understood how setinterval works but here I really can't figure out why for every iteration the setInterval doesn't works except for the last one, https://code.sololearn.com/WJiQQTum3Nl3/?ref=app
4 Réponses
+ 7
Using let keyword or passing "block" as argument are other alternatives to the method shared by Calviղ.
https://code.sololearn.com/WJqs565TCxgW/?ref=app
+ 3
setInterval callback is losing the block reference if it doesn't bind with the current block during iteration.
Get the block bind with the callback, eg. callbackFn.bind(block)
And call the binded block using "this" on callback function.
Check this out:
https://code.sololearn.com/WFdQM5M4VDlp/?ref=app
Read more on bind method https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind
+ 1
Ty very much everyone