// 实现setTimeout function mySetTimeout(fn, time, ...args) { const start = +new Date() let timer, now let loop = () => { timer = window.requestAnimationFrame(loop) now = +new Date() if(now - start >= time){ fn.apply(this, args) window.cancelAnimationFrame(timer) } } window.requestAnimationFrame(loop) } mySetTimeout(() => { console.log(3) }, 2000)