Skip to content
📁 标签
JavaScript手写题

节流函数

js
function debounce(fn, time = 500) {
    let timer = null;
    let context = this
    return function (...args) {
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => {
            fn.apply(context, args);
        }, time);
    };
}