Skip to content

Instantly share code, notes, and snippets.

@livimonte
Created January 3, 2013 18:38
Show Gist options
  • Save livimonte/4445784 to your computer and use it in GitHub Desktop.
Save livimonte/4445784 to your computer and use it in GitHub Desktop.
Event debouncer control.
var debouncer = function (func, pTimeout) {
var timeoutID, timeout = pTimeout || 200;
return function() {
var scope = this, args = arguments;
clearTimeout(timeoutID);
timeoutID = setTimeout(function() {
func.apply(scope, Array.prototype.slice.call(args));
}, timeout);
};
};
//sample
$(window).resize(debouncer(function(e) {
console.log('window resized');
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment