// Add this in HTML
<button id="myid">Click Me</button>
// This is JS Code for debounce function
const debounce = (fn,delay ) => {
let timeoutID; // Initially undefined
return function(...args){
// cancel previously unexecuted timeouts
if(timeoutID){
clearTimeout(timeoutID);
}
timeoutID = setTimeout( () => {
fn(...args);
}, delay)
}
}
document.getElementById('myid').addEventListener('click', debounce(e => {
console.log('you clicked me');
}, 2000))