Created
October 10, 2022 09:11
-
-
Save marekdano/02a984ffbbca3be1539357ce6f553e82 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(callback, timer) { | |
let timeoutId; | |
return (...args) => { | |
// save the current context (this) | |
const context = this; | |
// clear the existing timeout | |
clearTimeout(timeoutId); | |
// create a new timeout | |
timeoutId = setTimeout(() => { | |
callback.apply(context, args); | |
}, timer); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment