Skip to content

Instantly share code, notes, and snippets.

@mattosborn
Forked from danprince/debounce.js
Created November 12, 2015 13:40
Show Gist options
  • Save mattosborn/eac461aeacacca3bd0c9 to your computer and use it in GitHub Desktop.
Save mattosborn/eac461aeacacca3bd0c9 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