手写节流 throttle
// 节流就是「技能冷却中」
const d = () => { console.log('闪现') }
const throttle = (fn, time) => {
let 冷却中 = false
return (...args) => {
if(冷却中) return
fn(...args)
冷却中 = true
setTimeout(()=>{
冷却中 = false
}, time)
}
}
const d2 = throttle(d, 120*1000)
d2()