Skip to content

Instantly share code, notes, and snippets.

@abhaystoic
Last active March 3, 2020 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhaystoic/1cb2e7464ba2610c4aa449cc006e6b14 to your computer and use it in GitHub Desktop.
Save abhaystoic/1cb2e7464ba2610c4aa449cc006e6b14 to your computer and use it in GitHub Desktop.
const debounce = (func, delay) => {
let stop = false;
return (...args) => {
if (stop) {
setTimeout(() => {
stop = false;
}, 2000);
} else {
func(...args);
stop = true;
}
};
};
document.getElementById('myID').addEventListener(
'click',
debounce((e) => console.log('Clicked!!!'), 2000)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment