Skip to content

Instantly share code, notes, and snippets.

@Reanmachine
Created October 28, 2015 16:46
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 Reanmachine/43c45bdfdc24ae35ff3c to your computer and use it in GitHub Desktop.
Save Reanmachine/43c45bdfdc24ae35ff3c to your computer and use it in GitHub Desktop.
Micro Debounce
function Debounce(timeout) {
this._timeout = timeout;
this._registry = {};
}
Debounce.prototype.run = function(callback) {
var registry = this._registry;
if (registry[callback]) {
clearTimeout(registry[callback]);
}
registry[callback] = setTimeout(function() {
callback();
delete registry[callback];
}, this._timeout);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment