Skip to content

Instantly share code, notes, and snippets.

@guilhermepontes
Last active May 28, 2018 11:45
Show Gist options
  • Save guilhermepontes/01cd301255178c1ce851 to your computer and use it in GitHub Desktop.
Save guilhermepontes/01cd301255178c1ce851 to your computer and use it in GitHub Desktop.
Simple debounce in javascript
const debounce = function(fn, delay = 450) {
let timeout = null;
return () => {
timeout && clearTimeout(timeout);
timeout = setTimeout(fn.bind(this), delay, arguments);
};
};
// debounce(fn, 300)
// debounce(fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment