🌺
摘要
节流和防抖
节流和防抖
节流
function debounce(fn, wait) {
let timer = null
return function () {
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
fn.call(this, arguments)
}, wait)
}
}
防抖
function throttle(fn, wait) {
let timer = null
return function () {
if (!timer) {
timer = setTimeout(() => {
event()
timer = null
}, wait)
}
}
} 文章发表于 2024-04-15 16:00:00
作者:徐徐转载请注明出处