JS中的节流函数式编程-变量问题的范围

问题描述

我正在关注节流教程,这是那个家伙使用的代码。但是,我无法理解代码功能。每次调用节流阀时,不应该将最后一次设置为零吗?

const throttle = (fn,delay ) => {
    let last = 0
    return (...args) => {
        const Now = new Date().getTime();
        if(Now-last<delay){
            return;
        }
        last=Now; //how does this work - wouldn't last be set to zero the next time the function runs? 
        return fn(...args)
    }   
}
document.getElementById('myid').addEventListener('click',throttle(()=>{
    console.log('you clicked me')
},5000))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)