Debounce function
Run a function only after the calls have stopped for a moment.
JavaScript · Debounce functionIntermediate
function debounce(fn, delay = 300) {
let t;
return (...args) => {
clearTimeout(t);
t = setTimeout(() => fn(...args), delay);
};
}
window.addEventListener('resize', debounce(() => console.log('resized'), 250));performanceeventshelper