Last active
July 28, 2020 09:59
-
-
Save shcyiza/e64eb3bbf3d1d8318340f8e1b5d320a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Debounce(fn, wait = 300) { | |
this.timeout = null; | |
return (...args) => { | |
clearTimeout(this.timeout); | |
this.timeout = setTimeout(() => fn(...args), wait); | |
} | |
} | |
// Usage | |
const debounce = new Debounce(message => {console.log(message)}, 100); | |
debouncer("first"); | |
debouncer("2de"); | |
// expect: "2de" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment