functionthrottle(fn, wait =1000){let timer =null;let last =0;returnfunction(){let that =this;let args = arguments;let now = Date.now();if(last && now - last < wait){clearTimeout(timer);
timer =setTimeout(()=>{
last = now;fn.call(that,...args);}, wait);}else{
last = now;fn.call(that,...args);}}}