跳转至主要内容

C'est La Vie

JavaScript简单的防抖函数

hliang
最后编辑于 2020年7月20日

直接上代码:

function debounce(fn, time) {
    return function(args) {
        let that = this
        clearTimeout(fn.tid)
        fn.tid = setTimeout(() => {
            fn.call(that, args)
        }, time);
    }
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注