Created
December 11, 2013 10:23
-
-
Save zapthedingbat/7908110 to your computer and use it in GitHub Desktop.
Debouncer
Only executes the most recent call after the specified timeout.
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
// Only executes the most recent call after the specified timeout. | |
function Debouncer() { | |
var timeout; | |
this.execute = function(callback, wait) { | |
if (timeout) { | |
clearTimeout(timeout); | |
timeout = null; | |
} | |
timeout = setTimeout(callback, wait); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment