123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <!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 fn1() {
- // console.log(1);
- // await fn2();
- // console.log(2);
- // }
- // async function fn2() {
- // console.log("fn2");
- // }
- // fn1()
- // fn2();
- // console.log(3);
- // async function async1() {
- // console.log('async1 start')
- // await async2()
- // console.log('async1 end')
- // setTimeout(() => {
- // console.log('timer1')
- // }, 300)
- // }
- // async function async2() {
- // setTimeout(() => {
- // console.log('timer2')
- // }, 400)
- // console.log('async2')
- // }
- // async1()
- // setTimeout(() => {
- // console.log('timer3')
- // }, 200)
- // console.log('start')
- // async function fn1(){
- // console.log(333)
- // await fn2()
- // console.log(111)
- // }
- // async function fn2(){
- // throw new Error('rejected')
- // }
- // async function fn2(){
- // console.log(4)
- // }
- // fn1()
- // console.log(2222)
- // async function fn1(){
- // console.log(1)
- // await fn2()
- // console.log(2)
- // setTimeout(()=>{
- // console.log(3)
- // },1000)
- // }
- // async function fn2(){
- // console.log(4)
- // await fn3()
- // console.log(5)
- // setTimeout(()=>{
- // console.log(31)
- // },500)
- // }
- // async function fn3(){
- // setTimeout(()=>{
- // console.log(6)
- // },2000)
- // }
- // fn1()
- // console.log(7)
- async function a1() {
- console.log(4)
- await a2();
- console.log(1)
- }
- async function a2() {
- await console.log(2);
- await console.log(7)
- }
- a1();
- async function async1() {
- await async2();
- console.log("async1");
- return "async1 success";
- }
- async function async2() {
- return new Promise((resolve, reject) => {
- console.log("async2");
- reject("error");
- });
- }
- async1().then((res) => console.log(res));
- </script>
- </body>
- </html>
|