Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HelgaZhizhka/c39bd3e55e9c628f62476de47e49b825 to your computer and use it in GitHub Desktop.
Save HelgaZhizhka/c39bd3e55e9c628f62476de47e49b825 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