Skip to content

Instantly share code, notes, and snippets.

@darthwade
Created July 2, 2014 11:14
Show Gist options
  • Save darthwade/41f3687510a70945a047 to your computer and use it in GitHub Desktop.
Save darthwade/41f3687510a70945a047 to your computer and use it in GitHub Desktop.
Delayed function, throttle
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