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