群友出了一道 JS 异步顺序题😫

查看 52|回复 1
作者:xyxsw2023   
const async1 = async (resolve) => {
    console.log("async1 start")
    await async2()
    resolve()
    console.log("after resolve")
}
const async2 = async () => {
    console.log("async2")
}
console.log("after func define")
setTimeout(()=>{
    console.log("set timeout")
},0)
new Promise(async (resolve)=>{
    await async2()
    console.log("promise running")
    async1(resolve)
    console.log("promise end")
}).then(()=>{
    console.log("then start")
    setTimeout(()=>{
        console.log("timeout trigger")
    },0)
})
console.log("script end")

console, log, resolve, async2

weject   
毫无意义
您需要登录后才可以回帖 登录 | 立即注册

返回顶部