防抖节流实现
作者:互联网
1.防抖
function debounce(fun, time) { let timers; return function(){ clearTimeout(timers); let arg = arguments; timers = setTimeout( () => { fun.apply(this, arg) },time) } }
2.节流
function throttle(fun,time){ let t1=0 //初始时间 return function(){ let t2=new Date() //当前时间 if(t2-t1>time){ fun.apply(this,arguments) t1=t2 } } }
原文章:https://juejin.cn/post/7016502001911463950
标签:function,防抖,节流,实现,t2,t1,let,time,fun 来源: https://www.cnblogs.com/lcjspace/p/16448348.html