Skip to content

Instantly share code, notes, and snippets.

@350d

350d/debounce.js

Last active Aug 29, 2015
Embed
What would you like to do?
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