Last active
December 17, 2023 05:57
-
-
Save TorvaldsDB/e03915817f16b7fb377b5d70f5c28632 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
function debounce(func, delay) { | |
let timerId; | |
return function (...args) { | |
clearTimeout(timerId); | |
timerId = setTimeout(() => { | |
func.apply(this, args); | |
}, delay); | |
}; | |
} | |
// 使用用例 | |
const debounceFunction = debounce(() => { | |
console.log("Debounced function executed."); | |
}, 500); | |
// 调用 debounce 函数返回的函数,会在最后一次调用后延迟 500 毫秒执行 | |
debouncedFunction(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment