Skip to content

Instantly share code, notes, and snippets.

@cyan33
Created October 28, 2018 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyan33/33b69c7140dee48484ff96133e7ef353 to your computer and use it in GitHub Desktop.
Save cyan33/33b69c7140dee48484ff96133e7ef353 to your computer and use it in GitHub Desktop.
a simple debounce implementation
// I bounced into this debounce implementation today and
// think it's actually quite easy and simple
function debounce(fn, ms = 1000) {
let timeout = null;
return (...args) => {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => fn(...args), ms);
}
}
module.exports = debounce;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment