Created
December 26, 2022 15:54
-
-
Save gimmi/9588f8a616a6a4325a7c6b684b2e57c7 to your computer and use it in GitHub Desktop.
JavaScript
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
function debounce(func, timeout = 300) { | |
let timerId = null; | |
const debouncedFunc = (...args) => { | |
window.clearTimeout(timerId) | |
timerId = window.setTimeout(() => func(...args), timeout) | |
} | |
debouncedFunc.cancel = () => { | |
window.clearTimeout(timerId) | |
} | |
return debouncedFunc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment