promise.then( )返回的新promise的结果状态由什么决定?
<!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>


浙公网安备 33010602011771号