用setInterval实现setTimeout
function mySetTimout(fn, delay) {
const timer = setInterval(() => {
fn()
clearInterval(timer)
}, delay)
}
1
2
3
4
5
6
2
3
4
5
6
function mySetTimout(fn, delay) {
const timer = setInterval(() => {
fn()
clearInterval(timer)
}, delay)
}