内容纲要
// 概念:触发CD
let debounce = (fn, time, asThis) => {
let cooldown = false;
let timer = null;
return (...args) => {
if (cooldown) {
return;
}
fn.call(asThis, ...args)
cooldown = true;
timer = setTimeout(() => {
cooldown = false;
}, time)
}
}
const cp = debounce(() => {
console.log('调用成功');
}, 4000);