Created
January 2, 2025 10:21
-
-
Save PetukhovArt/dc9a689e32e6ce9ea5ba824fa9fc6282 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
// Нужно написать свой собственный метод debounce | |
function debounce(fn, timeout) { | |
let timeoutId = null; | |
return (...args) => { | |
clearTimeout(timeoutId); | |
timeoutId = setTimeout(() => { | |
if (typeof fn === "function") { | |
fn(...args); | |
} | |
}, timeout); | |
}; | |
} | |
const fetch = (args) => console.log("fetch", args); | |
const debounceFetch = debounce(fetch, 500); | |
debounceFetch(1); | |
debounceFetch(2); | |
debounceFetch(3); | |
debounceFetch(4); | |
debounceFetch(5); | |
debounceFetch(6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment