Skip to content

Instantly share code, notes, and snippets.

@poxrud
Created June 4, 2016 15:51
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 poxrud/f17c63febdd40cb1582e5ef56a6fb298 to your computer and use it in GitHub Desktop.
Save poxrud/f17c63febdd40cb1582e5ef56a6fb298 to your computer and use it in GitHub Desktop.
JS debounce
function debounce(func, delay) {
var alreadyScheduled;
var lastTimer;
return function() {
if (alreadyScheduled) {
clearTimeout(lastTimer);
}
alreadyScheduled = true;
lastTimer = setTimeout(function() {
func();
alreadyScheduled = false;
}, delay);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment