Last active
June 12, 2021 10:54
-
-
Save hayoung123/c30fe173fd29db1a8c1c27f0d25a474f to your computer and use it in GitHub Desktop.
쓰로틀링 & 디바운스
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
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