123456789101112131415161718192021222324252627282930 |
- <!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 等到异步对象执行完成之后 执行后续代码
- // await后必须是一个promise对象
- async function foo() {
- console.log("1")
- await new Promise(function(resolve,reject){
- setTimeout(function(){
- console.log(2)
- resolve()
- },1000)
- })
- console.log(3)
- }
- foo();
- </script>
- </body>
- </html>
|