跳到主要内容

setTimeout

function fakeTimeout(fn, time, ...args) {
let timer = null
const cancel = () => {
clearInterval(timer)
}
timer = setInterval(() => {
fn(...args)
cancel()
}, time)
return cancel
}

测试代码

fakeTimeout(
(...args) => {
console.log('end', ...args)
},
1000,
'a',
'b',
)