When opening the following HTML file in a browser, the timestamp is only logged once, why isn't the step function called a bunch of times per second as I would except?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<script>
function step(timestamp) { console.log(timestamp) }
window.requestAnimationFrame(step)
</script>
</body>
</html>
It only ever runs once. For it to repeat we must call requestAnimationFrame inside step for it to continue https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
Before:
function step(timestamp) {
console.log(timestamp)
}
window.requestAnimationFrame(step)
After:
let i = 0;
function step(timestamp) {
console.log(timestamp);
i++;
if (i < 10) {
window.requestAnimationFrame(step);
}
}
window.requestAnimationFrame(step)