Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice work. I'm not a JS expert but I think I saw a bug.

Inside of animate() you are calling setTimeout() to automatically call animate repeatedly but this is also calling setTimeout() every time animate runs but setTimeout() should only be run once.

You should be able to take

  setTimeout(() => {
    animate();
  }, 100);
and paste it over animate() on the last line


What you mean is setInterval and does work well for synchronous execution. His approach is correct and would even work if the animate function is asynchronous as the next tick gets scheduled at the end of animate function execution.


Ah yes, you are right. Got those mixed up.


Recursive setTimeout is a great way to allow for easy timing/speed changes on the fly.


good point :)




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: