背景

节流和防抖

徐徐
前端
发表于 2024-04-15 16:00:00
🌺 摘要
节流和防抖

节流和防抖

节流

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
作者:徐徐
转载请注明出处
上一篇:valueOf
下一篇:js生成随机数