Skip to content

Instantly share code, notes, and snippets.

@izifortune
Created December 8, 2015 14:56
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 izifortune/6845d77947270e9f0802 to your computer and use it in GitHub Desktop.
Save izifortune/6845d77947270e9f0802 to your computer and use it in GitHub Desktop.
var debounce = (func, wait, immediate) => {
let timeout;
return () => {
let context = this,
args = arguments;
let later = () => {
timeout = null;
if (!immediate) func.apply(context, args);
}
let callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment