28_async_await.html 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // setTimeout(()=>{
  11. // console.log("hello");
  12. // },1000)
  13. // console.log("world");
  14. //async await 异步优化解决方案
  15. // async 用来表示函数是异步的
  16. // await 用来表示紧跟在后面的表达式需要等待结果 等待的是一个promise对象
  17. // async function foo(){
  18. // await new Promise((resolve,reject)=>{
  19. // setTimeout(()=>{
  20. // resolve()
  21. // console.log("hello");
  22. // },1000)
  23. // })
  24. // console.log("world");
  25. // }
  26. // foo();
  27. // let foo = () => {
  28. // setTimeout(()=>{
  29. // console.log("hello");
  30. // },1000)
  31. // console.log("world");
  32. // }
  33. // foo();
  34. </script>
  35. </body>
  36. </html>