Skip to content

Instantly share code, notes, and snippets.

@genbliz
Created January 25, 2019 13:13
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 genbliz/f09497a256ab2012689090246a1f3cf9 to your computer and use it in GitHub Desktop.
Save genbliz/f09497a256ab2012689090246a1f3cf9 to your computer and use it in GitHub Desktop.
Simple JavaScript Debounce
var debounceTimeoutHolder = {};
function debounceSimple(id, wait, cb) {
if (debounceTimeoutHolder[id]) {
clearTimeout(debounceTimeoutHolder[id]);
}
debounceTimeoutHolder[id] = setTimeout(function() {
cb();
}, wait);
}
// Usage:
debounceSimple("d_01", 2000, function() {
// Next action here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment