1

对比一下setTimeout和Promise的实现方法,promise感觉更高大上。

setTimeout 实现

setTimeout(function() {
    console.log('1s')
    setTimeout(function() {
        console.log('2s')
    }, 1000)
}, 1000)
Promise 实现

const wait = () => new Promise((resolve, reject) => {
    setTimeout(resolve, 1000)
})
wait().then(() => {
    console.log('1s')
    return wait()
})
.then(() => console.log('2s'))


萌面大虾
9 声望1 粉丝