Skip to content

Instantly share code, notes, and snippets.

@hayoung123
Last active June 12, 2021 10:54
Show Gist options
  • Save hayoung123/c30fe173fd29db1a8c1c27f0d25a474f to your computer and use it in GitHub Desktop.
Save hayoung123/c30fe173fd29db1a8c1c27f0d25a474f to your computer and use it in GitHub Desktop.
쓰로틀링 & 디바운스
export const debounce = debounceInit();
//될지는 모르겠음
const debounce = (fn,wait) => {
let timer = null;
function debounced(){
if (timer) clearTimeout(timer);
timer = setTimeout(fn, wait);
}
return debounced;
}
export const throttle = (fn, time) => {
let timer = null;
return (e) => {
if (!timer) {
timer = setTimeout(function () {
timer = null;
fn(e);
}, time);
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment