Promise.resolve(1) .then(2) .then(Promise.resolve(3)) .then(console.log)運(yùn)行結(jié)果: 1解釋:.then 或者 .catch 的參數(shù)期望是函數(shù),傳入非函數(shù)則會(huì)發(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里面必須通過(guò)函數(shù)來(lái)返回的一個(gè)值才能被包裝為Promise嗎?
關(guān)于promise的一道面試題
九州編程
2019-02-13 17:17:44