Skip to content

Instantly share code, notes, and snippets.

@yyssjj33
Created July 27, 2017 23:08
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 yyssjj33/d640eaf606e1a07e9c15d92aa7a3bc3d to your computer and use it in GitHub Desktop.
Save yyssjj33/d640eaf606e1a07e9c15d92aa7a3bc3d to your computer and use it in GitHub Desktop.
const debounce = (fn, wait) => {
let timeout = null;
wait = wait || 250; // Default to 250ms
return (...args) => {
const delayed = () => {
timeout = null;
fn.apply(null, args);
};
clearTimeout(timeout);
timeout = setTimeout(delayed, wait);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment