Created
October 28, 2015 16:46
-
-
Save Reanmachine/43c45bdfdc24ae35ff3c to your computer and use it in GitHub Desktop.
Micro Debounce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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