Skip to content

Instantly share code, notes, and snippets.

@350d
Last active August 29, 2015 14:03
Show Gist options
  • Save 350d/99ae183c9fa569b69314 to your computer and use it in GitHub Desktop.
Save 350d/99ae183c9fa569b69314 to your computer and use it in GitHub Desktop.
Javascript debounce
Function.prototype.debounce = function(delay) {
var timeout, callback = this;
return function() {
clearTimeout(timeout);
timeout = setTimeout(callback, delay);
}
}
window.addEventListener('resize',test.debounce(200));
// OR
$(function(){
$(window).resize(test.debounce(200));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment