编辑代码

function debounce(fn, wait) {
    let timer = null;
    return function(...arg) {
        const that = this;
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => {
            fn.call(that, arg);
        }, wait)
    }
}


function throttle(fn, wait) {
    let preDate = null;

    return function(...arg) {
        const that = this;
        const now = Date.now();
        if (now - preDate > wait) {
            preDate = now;
            return fn.apply(that, arg);
        }
    }
}