Skip to content

Instantly share code, notes, and snippets.

@danprince
Created January 29, 2015 11:14
Show Gist options
  • Save danprince/d4331e50088acc0cdd65 to your computer and use it in GitHub Desktop.
Save danprince/d4331e50088acc0cdd65 to your computer and use it in GitHub Desktop.
Debounce
function debounce(fn, interval) {
var lastCall;
return function() {
var now = Date.now();
if(!lastCall || now - lastCall > interval) {
fn.apply(this, arguments);
lastCall = now;
}
};
}
function hello() {
return console.log('hello world');
}
setInterval(debounce(hello, 2000), 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment