In the following throttle function, timeout eventually turns into a number as it's assigned to the setTimeout. I'm redefining it as false as it's cleared, the code works.
I don't notice anything on the surface, but wondering if there are any issues with doing things this way or there's something I might be missing?
const throttle = (fn, delay) => {
let timeout;
return (...args) => {
if(!timeout) {
timeout = setTimeout(() => {
fn(...args);
clearTimeout(timeout = false);
}, delay);
}
}
};