Created
March 26, 2013 11:52
-
-
Save connrs/5244842 to your computer and use it in GitHub Desktop.
Callback delay with reset
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
// I just wanted a quick reference for this function as it's a common pattern | |
// used when managing DOM events that may fire multiple times in a short period | |
// of time. | |
function delayWithReset(delayMilliseconds, callback) { | |
var timeout = null; | |
var func = function() { | |
var args = Array.prototype.slice.apply(arguments); | |
window.clearTimeout(timeout); | |
timeout = window.setTimeout(function () { | |
callback.apply(null, args); | |
}, delayMilliseconds); | |
}; | |
return func; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment