Skip to content

Instantly share code, notes, and snippets.

@sungchuni
Last active December 7, 2020 14:30
Show Gist options
  • Save sungchuni/404de6bc003834af253cb562666835dc to your computer and use it in GitHub Desktop.
Save sungchuni/404de6bc003834af253cb562666835dc to your computer and use it in GitHub Desktop.
simple implementation throttle
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