Skip to content

Instantly share code, notes, and snippets.

@rijkvanzanten
Last active March 2, 2022 03:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rijkvanzanten/da0131fb5513b8c3c819dc09c572bc99 to your computer and use it in GitHub Desktop.
Save rijkvanzanten/da0131fb5513b8c3c819dc09c572bc99 to your computer and use it in GitHub Desktop.
Small debounce function, based on David Walsh's original
function debounce(callback, wait) {
var timeout;
return function() {
var context = this;
var args = arguments;
var later = function() {
timeout = null;
}
var callNow = !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) callback.apply(context, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment