-
Notifications
You must be signed in to change notification settings - Fork 0
/
手写promise.html
62 lines (60 loc) · 1.58 KB
/
手写promise.html
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
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
async function async1() {
console.log("async1 start");
await new Promise((resolve) => {
console.log("promise1");
resolve("promise resolve");
});
console.log("async1 success");
return "async1 end";
}
console.log("srcipt start");
async1().then((res) => {
console.log(res);
});
new Promise((resolve) => {
console.log("promise2");
setTimeout(() => {
console.log("timer");
});
});
console.dir(async1);
// console.log(result);
// async function foo1() {
// return 1;
// }
// async function foo2() {
// return Promise.resolve(
// new Promise((res, rej) => {
// res(20);
// })
// );
// }
// async function foo3() {
// throw new Error("error");
// }
// async function foo4() {}
// console.log(foo1());
// console.log(foo2());
// console.log(foo3());
// console.log(foo4());
</script>
</body>
</html>
<!--
console.log("promise1里的内容");
console.log("promise1", promise1);
console.log("promise2", promise2);
throw new Error("error!!!");
console.log("timer1");
console.log("timer2");
console.log("promise1", promise1);
console.log("promise2", promise2); -->