// 节流
// 在函数需要频繁触发时: 函数执行一次后,只有大于设定的执行周期后才会执行第二次
function throttle(callback,wait){
let start = 0;
return function(event){
const current = Date.now();
if(current - start > wait){
callback.call(this,event);
start = current
}
}
}
// 防抖 在函数需要频繁触发时: 在规定时间内,只让最后一次生效,前面的不生效。
function debounce(callback, wait){
let time = null;
return function (event){
if(!null){
clearTimeout(time);
}
time = setTimeout(()=>{
callback.call(this,event);
time = null;
},wait)
}
}