// Vanilla Debounce implementation function debounce(func, wait = 100) { let timeout; return function(...args) { clearTimeout(timeout); timeout = setTimeout(() => { func.apply(this, args); }, wait); }; } function sayHi(event) { console.log('Hi!', this, event.type); } // Start const debounced = debounce(sayHi, 500); window.addEventListener('resize', debounced); document.body.addEventListener('click', debounced)