亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Promise.resolve的參數是thenable對象時

Promise.resolve的參數是thenable對象時

慕碼人2483693 2019-01-29 23:23:26
http://es6.ruanyifeng.com/#do...這個是阮一峰老師關于Promise.resolve()參數的解讀,其中參數是thenable對象時,Promise.resolve方法會將這個對象轉為 Promise 對象,然后就立即執行thenable對象的then方法。問題來了:new Promise(resolve => {resolve(1);Promise.resolve({    then: function(resolve, reject){        console.log(2);         resolve(3)     } }).then(t => console.log(t))console.log(4);}).then(t => console.log(t));console.log(5);控制臺輸出:4 5 2 1 3下面按照最開始的理解,將上述代碼進行轉換new Promise(resolve => {resolve(1);new Promise(resolve=>{    console.log(2);     resolve(3) }).then((t) => console.log(t));console.log(4);}).then(t => console.log(t));console.log(5);控制臺輸出 2 4 5 3 1
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 819 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號