3 ms·
In the case of animations, if you call the main animation loop from inside the loop you will quickly get a "too much recursion" / "maximum call stack size excee
by perilunar 8y ago
In the case of animations, if you call the main animation loop from inside the loop you will quickly get a "too much recursion" / "maximum call stack size exceeded" error.
e.g.
function main() {
// do animation stuff
main();
}
Will throw an error. If you do the following:
function main() {
// do animation stuff
window.setTimeout(main, 0);
}
You wont get the error, because main() is being called by window instead, so is not recursive.
(window.requestAnimationFrame is usually better for animation though).