+ 1
How does this code work even the call to draw does not have arguments?
Code from MDN https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Timeouts_and_intervals let startTime = null; function draw(timestamp) { if(!startTime) { startTime = timestamp; } currentTime = timestamp - startTime; requestAnimationFrame(draw); } draw();
2 ответов
+ 3
Because window.requestAnimationFrame(step) takes a callback step with timestamp set to the first augument.
Check out this simple code to see how window.requestAnimationFrame(step) get the timestamp when it run.
https://code.sololearn.com/WpQ8JrlfcLW7/?ref=app
+ 1
Thanks Calviղ