Created
April 17, 2020 16:03
-
-
Save mr4torr/5c76fbcd848ef72e81a3adb612b7ed10 to your computer and use it in GitHub Desktop.
debounce in javascript pure - es6
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 debounceEvent = (fn, wait = 500, time) => (...args) => clearTimeout(time, time = setTimeout(() => fn(...args), wait)) | |
/* | |
Example: | |
document.querySelector('input').addEventListener('keyup', debounceEvent((event) => console.log(event))) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment