1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
function promiseFn(item){
return new Promise((resolve,reject)=>{
setTimeout(()=>{
if(item){
resolve("成功");
}else{
reject("失敗");
}
},1000)
})
}
promiseFn(1)
.then((res)=>{
console.log("一號成功"); //一號成功
return promiseFn(2)
},(rej)=>{
console.log("一號失敗");
return promiseFn(2)
})
.then((res)=>{
console.log("二號成功"); //二號成功
return promiseFn(3)
},(rej)=>{
console.log("二號失敗");
return promiseFn(3)
})
.then((res)=>{
console.log("三號成功"); //三號成功
return promiseFn(0)
},(rej)=>{
console.log("三號失敗");
return promiseFn(0)
})
.then((res)=>{
console.log("四號成功");
},(rej)=>{
console.log("四號失敗"); //四號失敗
})
|