debounceFunction() {
let timeout = setTimeout(() => {
doSomething();
flag = true;
clearTimeout(timeout);
}, 250);
}
I wrote a debounce function that looks like the above, I called this function for several times when an event is triggered. My question is, does the clearTimeout at the end of the setTimeout makes any sense?
What would be the optimal way to do it?
Thanks in advance :)