Last active
September 6, 2016 06:15
-
-
Save pokka/5335363 to your computer and use it in GitHub Desktop.
simple delay javascript function,when you care about duplicate execute
This file contains hidden or 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
let timer; | |
const delay = (func, ms = 500) => { | |
clearTimeout(timer); | |
timer = setTimeout(func, ms); | |
} | |
export default delay; |
This file contains hidden or 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 delay = (function(){ | |
var timer; | |
return function(func, ms){ | |
clearTimeout(timer); | |
timer = setTimeout(func, ms); | |
}; | |
})(); | |
// USAGE | |
// delay(function(){console.log("you won't see me")},1000); | |
// delay(function(){console.log("you won't see me")},1000); | |
// delay(function(){console.log("here!")},1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment