Track setTimeout IDs so one call clears every pending timeout
Imagine you’re tasked with scheduling tasks for future execution in a frontend environment, utilizing the window.setTimeout() function. Your challenge doesn’t stop there; you must also create a function named clearAllTimeout(). This function should be capable of clearing all active timers, ensuring a clean slate of pending tasks, particularly useful during page transitions. The native clearTimeout() only clears one timeout at a time.
Consider the scenario where you’ve scheduled multiple functions for execution after a 10-second delay:
setTimeout(func1, 10000);
setTimeout(func2, 10000);
setTimeout(func3, 10000); // All three functions are set to execute after 10 seconds.
The requirement is to halt all these scheduled tasks with a single call to clearAllTimeout():
clearAllTimeout(); // This call should cancel all previously scheduled tasks.
Your solution must adhere to the existing interface of window.setTimeout and window.clearTimeout, but you are encouraged to redefine their underlying implementations. This exercise will test your ability to manipulate timers efficiently in a frontend development context, showcasing your skills in managing asynchronous tasks.
Through this challenge, you’ll demonstrate not only your proficiency in using JavaScript timers but also your innovative approach to enhancing and controlling their behavior to suit specific application needs.