Promise.resolve(1)
.then(2)
.then(Promise.resolve(3))
.then(console.log)運行結果: 1解釋:.then 或者 .catch 的參數期望是函數,傳入非函數則會發生值穿透。Promise.resolve(1)
.then(function(){return 2})
.then(Promise.resolve(3))
.then(console.log)結果為2Promise.resolve(1)
.then(function(){return 2})
.then(function(){return Promise.resolve(3)})
.then(console.log)結果為3不是太明白,then里面必須通過函數來返回的一個值才能被包裝為Promise嗎?
關于promise的一道面試題
慕桂英4014372
2018-08-03 08:25:25