- Debouncing: Ensures that a function is only executed after a certain period has passed since it was last invoked.
function debounce(func, delay) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), delay);
};
}
window.addEventListener('resize', debounce(() => {
console.log('Resized!');
}, 300));