forked from webVueBlog/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromise的单一状态与中转.js
53 lines (46 loc) · 899 Bytes
/
promise的单一状态与中转.js
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
42
43
44
45
46
47
48
49
50
51
52
53
let p1 = new Promise((resolve, reject) => {
resolve('成功随风倒十分');
});
new Promise((resolve, reject) => {
//状态一旦设置不会改变
resolve(p1);
reject('sfd');
}).then(
(msg) => {
console.log(msg);
},
(error) => {
console.log(error);
}
);
console.log('测试');
let p21 = new Promise((resolve, reject) => {
resolve('fulfilled');
});
let p4 = p21.then(
(value) => {
return {
then(resolve, reject) {
resolve('套娃1');
},
};
},
(reason) => console.log(reason)
);
let p6 = p4.then((v) => {
console.log(v);
return {
then(resolve, reject) {
resolve('套娃2');
},
};
});
let p7 = p6.then((v) => {
console.log(v);
});
// setTimeout(() => {
console.log(p21);
console.log(p4);
console.log(p6);
console.log(p7);
// });