Skip to content

Instantly share code, notes, and snippets.

@abhaystoic

abhaystoic/debounce.js

Last active Mar 3, 2020
Embed
What would you like to do?
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