Skip to content

Instantly share code, notes, and snippets.

@xfsnowind
Created October 23, 2015 22:31
Show Gist options
  • Select an option

  • Save xfsnowind/cc857bda15605b275716 to your computer and use it in GitHub Desktop.

Select an option

Save xfsnowind/cc857bda15605b275716 to your computer and use it in GitHub Desktop.
debounce method on blog "Introducing Javascript method debounce" on 2014/05/12
function debounce(func, wait, immediate) {
var timeout;
return function () {
var obj = this, argus = arguments;
function delayed () {
if (!immediate) {
func.apply(obj, argus);
}
timeout = null;
}
if (timeout) {
clearTimeout(timeout);
} else if (immediate) {
func.apply(obj, argus);
}
timeout = setTimeout(delayed, wait);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment