Skip to content

Instantly share code, notes, and snippets.

@airyboy
Last active August 4, 2017 13:32
Show Gist options
  • Save airyboy/f9389813687203560cfa7b08921af16b to your computer and use it in GitHub Desktop.
Save airyboy/f9389813687203560cfa7b08921af16b to your computer and use it in GitHub Desktop.
var myFun = debounce(() => console.log('call'), 1000);
myFun();
myFun();
myFun(); //only this call will be called
function debounce(fn, delay) {
let isActivated = false;
return function() {
if (!isActivated) {
isActivated = true;
setTimeout(() => {
fn();
isActivated = false;
}, delay);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment