Forked from vinchik/debounce-simple-implementation.js
Created
September 6, 2022 10:46
-
-
Save HelgaZhizhka/c39bd3e55e9c628f62476de47e49b825 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