4 ms·
> 1) window.requestAnimationFrame(main): It calls main function. No. It's not "calling" main. It is scheduling a future invocation of main outside of the curre
by bob1029 4y ago
> 1) window.requestAnimationFrame(main): It calls main function.
No. It's not "calling" main. It is scheduling a future invocation of main outside of the current execution context. The return value of that function is a handle that lets you cancel the scheduled invocation, if desired.
In terms of concepts, this is related to the event loop and callback mechanisms. Maybe check this article out: https://www.digitalocean.com/community/tutorials/understanding-the-event-loop-callbacks-promises-and-async-await-in-javascript https://www.digitalocean.com/community/tutorials/understandi...
- shivajikobardan 4y agocan someone please build some visualization for me for this? A simple sketch will work.
- beardyw 4y agoThe above explains it. I am not sure a diagram will help. In the simplest of terms, your code will run until it has no more to do. If you set something else running (like request animation frame or fetch from the server) it may be doing something in parallel but the JavaScript code associated with it will only run when its turn comes. Only one part of your code is ever running at a time. You can run code in parallel yourself by creating a new environment called a worker but that is more advanced.
- shivajikobardan 4y agodiagram helps. I don't have time to share it by pasting to imgur here, but you can check this thread. https://forum.kirupa.com/t/why-does-if-condition-executes-in-this-requestanimationframe-code/656074/5 https://forum.kirupa.com/t/why-does-if-condition-executes-in...