+ 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

18th Jul 2020, 11:10 PM
Abhay
Abhay - avatar
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
19th Jul 2020, 6:32 AM
Kevin ★
+ 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
19th Jul 2020, 6:12 AM
Calviղ
Calviղ - avatar
+ 1
Ty very much everyone
19th Jul 2020, 8:52 AM
Abhay
Abhay - avatar