编辑代码

//程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。 
function throttle(func, wait = 50) {
    let lastTime = 0;
    return function(...args) {
        const now = +new Date();
        const context = this;
        if (now - lastTime > wait) {
            func.apply(this, args);
            lastTime = now;
        }
    }
}
function sum(a, b) {
    console.log(a+b);
    return a + b;
}
// throttle(sum, 5000)(3, 4);
setInterval(throttle(sum, 5000), 1, 3, 4);