Last active
December 7, 2020 14:30
-
-
Save sungchuni/404de6bc003834af253cb562666835dc to your computer and use it in GitHub Desktop.
simple implementation throttle
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
function throttle(fn, wait) { | |
let timestamp = -wait || 0; | |
return function throttled(...args) { | |
const now = performance.now(); | |
now - timestamp > wait && (timestamp = now) && fn.apply(this, args); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment