Created
October 20, 2016 20:27
-
-
Save anaibol/b511550e0d6faed05bf777a50ed37e59 to your computer and use it in GitHub Desktop.
ES6 debounce
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
export default function debounce(func, wait, immediate) { | |
let timeout | |
return function(...args) { | |
clearTimeout(timeout) | |
timeout = setTimeout(() => { | |
timeout = null | |
if (!immediate) func.apply(this, args) | |
}, wait) | |
if (immediate && !timeout) func.apply(this, [...args]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2023