5_立即执行函数.html 639 B

12345678910111213141516171819202122232425262728
  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. // 立即执行函数
  11. // 将一个匿名函数赋值给一个变量
  12. // var foo = function(){
  13. // console.log("hello world");
  14. // }
  15. // foo();
  16. // 实现立即执行函数的两种方法
  17. (function(){
  18. console.log("hello world");
  19. }());
  20. // 或者
  21. (function(){
  22. console.log("hello world");
  23. })();
  24. </script>
  25. </body>
  26. </html>