let promise1 = Promise.resolve() .then(res => console.log(1)) .then(res => console.log(2)) let promise2 = new Promise(resolve => { setTimeout(() => { console.log(6) resolve() }) }).then(res => console.log(3)) async function main() { console.log(4) console.log(await Promise.all([promise2, promise1])) console.log(5) return { obj: 5 } } let promise3 = Promise.resolve() .then(res => console.log(8)) .then(res => console.log(9)) console.log(typeof main())
碰到了一道前端promise的笔试题,有点绕,想不明白,有哪个大佬能讲解一下吗?🤣🤣
运行结果如下:
全部评论
(4) 回帖