So I have a simple function:
var start = function(){
lastFrame = performance.now();
requestAnimationFrame((t)=>{interval(t)});
}
And my interval function (just for test purposes I have clogged the values of each rAF stamp)
function interval(t){
console.log (t);
console.log(lastFrame);
}
Now I have read the following response to another question but I just can't understand a few parts of this person's answer.
The timestamp passed in to the requestAnimationFrame() callback is the time of the beginning of the animation frame. Multiple callbacks being invoked during the same frame all receive the same timestamp. Thus, it would be really weird if performance.now() returned a time before the parameter value, but not really weird for it to be after that.
"it would be really weird if performance.now() returned a time before the paramter value" ?
Why would this be weird? I thought Javascript was an interpreted language? At this point:
lastFrame = performance.now();
The browser doesn't even now about the next line:
requestAnimationFrame((t)=>{interval(t)});
Surely if you make a call to performance.now() before you even provide a callback for your requestAnimationFrame the time of lastFrame should be less than the t passed into requestAnimationFrame?
In this person's response, he lays out a 6 step process involved with requesting an animation frame. However, he lists the performance.now() call as the last step.
How can it be the last step when it has been interpreted by the browser before the animationFrame request?
performance.now
from inside theinterval
function, not fromstart
. – Coventry