js 函数
延迟执行
function debounce(wait) {
var timer = null;
return function (fn) {
if (timer !== null) {
clearTimeout(timer);
}
timer = setTimeout(fn, wait);
};
}
let debounced = debounce(3000);
debounced(()=>{
console.log("1");
})
setTimeout(()=>{
debounced(()=>{
console.log("2");
})
},2000)