25_异步.html 820 B

123456789101112131415161718192021222324252627282930313233
  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. // alert(1);
  11. // console.log("hello");
  12. // 任务队列 事件循环 event loop
  13. // 异步方法 setTimeout setInterval
  14. // 如果js发现异步方法无论等多久都会将它放到异步的任务队列当中,先执行同步代码
  15. // setTimeout(function(){
  16. // console.log("world");
  17. // },0);
  18. // console.log("hello");
  19. function foo(timer,fun){
  20. setTimeout(function(){
  21. fun();
  22. },timer)
  23. }
  24. foo(2000,function(){
  25. console.log("world");
  26. });
  27. </script>
  28. </body>
  29. </html>