當調用一個 async 函數時,會返回一個 promise 對象 (關鍵)
async 函數中可能會有 await 表達式,await表達式 會使 async 函數暫停執行,直到表達式中的Promise解析完成後繼續執行 async 中 await 後面的代碼並返回解決結果。
既然返回的是Promise 對象,所以在最外層不能直接獲取其返回值,那麼肯定可以用原來的方式:then() 鏈來處理這個 Promise 對象
原理:
async/await 函數其實就是一種語法糖
async/await 是基於promise實現的,async 函數其實就是把 promise 做了一個包裝
await 返回值是一個 Promise 對象,它只是把 await 後面的代碼放到了 ()