Created
July 2, 2014 11:14
-
-
Save darthwade/41f3687510a70945a047 to your computer and use it in GitHub Desktop.
Delayed function, throttle
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.prototype.delayed = function (delay) { | |
var timer = 0; | |
var callback = this; | |
return function() { | |
clearTimeout(timer); | |
timer = setTimeout(callback, ms); | |
}; | |
}; | |
document.getElementById('search').addEventListener('keyup',search.delayed(200)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment