If you don't have much time, tell me from where the 'newTime' argument gets its value in the code below.
Look at the code below to understand. I don't understand how the line : requestAnimationFrame(newTime => animate(newTime,time))
works. The argument 'newTime' has never been declared and we don't pass a value to it manually either.
The same problem occurs while i try to understand different array methods, usually an argument is passed and used inside the function but the value of argument is always unknown to me. For example this snippet `array1.map(x => x * 2);. We never pass the 'x' and we never know its value.
Here's the code:
let cat = document.querySelector("img");
let angle = Math.PI / 2;
function animate(time, lastTime) {
if (lastTime != null) {
angle += (time - lastTime) * 0.001;
}
cat.style.top = (Math.sin(angle) * 20) + "px";
cat.style.left = (Math.cos(angle) * 200) + "px";
requestAnimationFrame(newTime => animate(newTime, time));
}
requestAnimationFrame(animate);