Last active
September 6, 2022 10:46
-
-
Save vinchik/c3981fe04f0e97f34e56e5a70e193d86 to your computer and use it in GitHub Desktop.
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
function debounce(originalFn, timeoutMs) { | |
let timeout; | |
return (...args) => { | |
clearTimeout(timeout); // clear timeout every time the function is called | |
timeout = setTimeout(() => originalFn(...args), timeoutMs); // call the original function once "timeoutMs" ms after the last call have elapsed | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment