Last active
August 4, 2017 13:32
-
-
Save airyboy/f9389813687203560cfa7b08921af16b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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