Skip to content

📚 11.setInterval模拟setTimeOut

💻 代码实现

typescript
function myTimeOut(cb, delay) {
    const timer = setInterval(() => {
        cb()
        clearInterval(timer)
    }, delay)
}
myTimeOut(() => console.log(111111), 1000)

Released under the MIT License.