0

I'm having a hard time understanding this code below:

<p style="text-align: center">
    <img src="http://nobacks.com/wp-content/uploads/2014/11/Cat-44-490x500.png" style="position: relative">
</p>
<script>
    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);
</script>

The outcome is a cat picture spinning in circles. My confusion comes from this part:

requestAnimationFrame(newTime => animate(newTime, time));

What does newTime => animate(newTime, time) do?

Satpal
  • 126,885
  • 12
  • 146
  • 163
Richard Yang
  • 111
  • 1
  • 2
  • 5
  • Are you asking what an arrow function is or what `animate` does? – VLAZ Oct 24 '18 at 06:44
  • To what extent do and don't you understand it? – deceze Oct 24 '18 at 06:44
  • `requestAnimationFrame(newTime => animate(newTime, time));` is just another way to write `requestAnimationFrame((function(newTime) { return animate(newTime, time)}).bind(this)); ` – Ayush Gupta Oct 24 '18 at 06:46

0 Answers0