Skip to content

Instantly share code, notes, and snippets.

@cyan33
Created March 12, 2019 18:09
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/32cd3853efc25bdaf0c93d2640c35dbc to your computer and use it in GitHub Desktop.
Save cyan33/32cd3853efc25bdaf0c93d2640c35dbc to your computer and use it in GitHub Desktop.
debounce.js
function debounce(fn, delay = 1000) {
let timeoutId = null;
return () => {
if (timeoutId) {
timeoutId = null;
}
timeoutId = setTimeout(fn, delay);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment