//防抖机制 在3秒内 只有第一次点击生效,其它无效再过了3秒后循环(第一人说了算)
var num = 0;
function throttle(fn,interval){
let last = 0;
return function(){
let context = this;
let args = arguments;
let now = +new Date();
console.log(now,last,fn, 'now')
if(now-last >= interval){
last = now;
fn.apply(context,args);
}
}
}
document.addEventListener('click',throttle(() =>{num++;console.log(num,'num')} ,3000));