Last active
March 3, 2020 16:07
-
-
Save abhaystoic/1cb2e7464ba2610c4aa449cc006e6b14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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