async 与 await 的用法详解

黄琦雲 at 
async 概念用于声明异步函数,返回值为一个 Promise 对象,它以类似 同步 的方式来写异步方法,语法与声明函数类似,例如:async function fn() { console.log('Hello world!');}console.log(fn().constructor); // Promise()// 这里证明其返回值为一个 Promise 对象;返回值也许这里会有疑问,返回值是 Promise 对象,那么函数本身定义的返回值跑到哪里去了呢?其实,熟悉 Promise 的就知道其异步结果是通过 .then() 或者 .catch() 方法来获取并进行进一步处理的,这……