<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>promise</title> </head> <body> <script> // promise.then( )返回的新promise的結果狀態由什么決定? // (1)簡單表達:由then()指定的回調函數執行的結果決定 // (2)詳細表達: // @如果拋出異常,新promise變 為rejected, reason為拋出的異常 // ②如果返回的是非promise的任意值,新promise 變為resolved, value 為返回的值 // ③如果返回的是另一 個新promise,此promise的結果就會成為新promise的結果 new Promise((resolve,reject) =>{ resolve(1) }) .then(value1 =>{ console.log('onResolve1()',value1) // return undefined // return Promise.resolve(222) throw 6 // return //什么都不寫就相當於返回一個undefined },reason1 =>{ console.log('onRejectd1()',reason1) }) .then(value2 =>{ console.log('onResolve2()',value2) },reason2 =>{ console.log('onRejectd2()',reason2) }) .then(value3 =>{ console.log('onResolve3()',value3) },reason3 =>{ console.log('onRejectd3()',reason3) }) </script> </body> </html>