文章预览
0、前言 关于 promise、async/await 的使用相信很多小伙伴都比较熟悉了,但是提到 事件循环机制输出结果 类似的题目,你敢说都会? 试一试? 🌰1: async function async1 ( ) { await new Promise ( ( resolve, reject ) => { resolve() }) console .log( 'A' ) } async1() new Promise ( ( resolve ) => { console .log( 'B' ) resolve() }).then( () => { console .log( 'C' ) }).then( () => { console .log( 'D' ) }) // 最终结果👉: B A C D 🌰2: async function async1 ( ) { await async2() console .log( 'A' ) } async function async2 ( ) { return new Promise ( ( resolve, reject ) => { resolve() }) } async1() new Promise ( ( resolve ) => { console .log( 'B' ) resolve() }).then( () => { console .log( 'C' ) }).then( () =>
………………………………