| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <!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 await
- // function foo(){
- // setTimeout(() => {
- // console.log("hello world");
- // }, 2000);
- // console.log("你好");
- // }
- // foo()
- // async await 语法糖
- // async 可以将行数改为异步函数
- // await 一定要写在 async 函数内 async/await一定要组合使用
- async function foo() {
- // 等待异步操作完成
- // 异步操作完成后,继续执行后续代码
- // await后边需要等待一个Promise对象
- await new Promise((resolve, reject) => {
- setTimeout(() => {
- console.log("hello world");
- resolve();
- }, 2000);
- })
- console.log("你好");
- }
- foo()
- </script>
- </body>
- </html>
|