// 防抖和节流// 使用方法:// let exportFunct = throttle(this.exportExcel,5000)// exportFunct(传参数)// 如果没有参数:exportFunct()exportfunctiondebounce(fn, wait){returnfunction(args){//获取函数的作用域和变量let that =thislet _args = args
//每次事件被触发,都会清除当前的timer,然后重写设置超时调用clearTimeout(fn.id)
fn.id =setTimeout(function(){fn.call(that, _args)}, wait)}}exportfunctionthrottle(fn, wait, delay){let last,
deferTimer =nullreturnfunction(){let that =thislet _args = arguments
let now =+newDate()if(last && now < last + delay){clearTimeout(deferTimer)
deferTimer =setTimeout(function(){
last = now
fn.apply(that, _args)}, wait)}else{console.log(32,3222)
last = now
fn.apply(that, _args)}}}