function throttle(fn, delay) {
let last = 0 // 上次触发时间
return (...args) => {
console.log(args)
// console.log(this)
const now = Date.now()
if (now - last > delay) {
last = now
fn.apply(this, args)
}
}
}
// 测试
function task(name) {
console.log(name)
console.log('run task')
}
const throttleTask = throttle(
task
, 1000)
<button onclick="throttleTask(999)">按钮</button>