Just stumbled across a comment in this very old question regarding clearing all setTimeouts.
The comment has intrigued me as it doesn't actually address the question directly, but offers a really interesting alternative solution to the problem of keeping track of multiple timers, but sadly he offers no example of how this could be implemented :
Use a global timeout which all of your other functions derive timing from. This will make everything run faster, and be easier to manage, although it will add some abstraction to your code...
... I just meant that you have one global timeout running once every 50ms. Every other function which would require a timing element would then grab it from the global timeout. Google switched to this for efficiency, although I can no longer find the article quoting it.
How would one go about setting what I assume is a named timer in the global space and then referencing it elsewhere in multiple cases?
For example if we had something like this in the global space :
let myGlobalTimer = setTimeout(function(){ myFunc(); }, 50);
That would only run myFunc
every 50ms.
I'm pretty sure you can't pass dynamic function names into setTimeout
so how would one achieve this?