Skip to content

Instantly share code, notes, and snippets.

@vinchik
Last active September 6, 2022 10:46
Show Gist options
  • Save vinchik/c3981fe04f0e97f34e56e5a70e193d86 to your computer and use it in GitHub Desktop.
Save vinchik/c3981fe04f0e97f34e56e5a70e193d86 to your computer and use it in GitHub Desktop.
debounce
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