varthrottle=function(func,delay){ varprev=Date.now(); returnfunction(){ varcontext=this; varargs=arguments; varnow=Date.now(); if(now-prev>=delay){ func.apply(context,args); prev=Date.now(); } }}functionhandle(){ console.log(Math.random());}window.addEventListener('scroll',throttle(handle,1000));两个date.now()是怎么运行的原理是什么
潇湘沐
相关分类