Consider this snippet.
function debounce(fn, delay) {
let id;
return (...args) => {
clearTimeout(id);
setTimeout(() => fn(...args), delay);
};
}
const log = debounce(console.log, 300);
log('first');
log('second');
Why might this still behave unexpectedly in a UI input flow, and what tiny fix would you make.
Quelly