编辑代码

function debounce (fn, delay) {
    let timer = null;
    const _debounce = function (...args) {
        if (timer) clearTimeout(timer);
        timer = setTimeout (() => {
            fn.call(this, ...args);
        }, delay);
    };
    return _debounce;
}

function throttle (fn, delay) {
    let last = 0;
    const _throttle = function (...args) {
        const now = new Date().getTime();
        if (now - last >= delay) {
            fn.call(this, ...args);
            last = now;
        }
    };
    return _throttle;
}