Created
April 15, 2018 01:07
-
-
Save karenpeng/c339bfedb1da29607053db0d249a7fd8 to your computer and use it in GitHub Desktop.
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
const throttle = (func, delay) => { | |
let executable = true; | |
return () => { | |
if (executable) { | |
func(); | |
executable = false; | |
setTimeout(() => { | |
executable = true; | |
}, delay); | |
} | |
}; | |
} | |
const debounce = (func, delay) => { | |
let lastTimeStamp = Infinity; | |
return () => { | |
const now = Date.now(); | |
if (lastTimeStamp - now > delay) { | |
func(); | |
} | |
lastTimeStamp = now; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment