06.作用域练习1.html 829 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. //测试题1
  12. // var x = 10
  13. // function fn(){
  14. // console.log(x)
  15. // }
  16. // function show(f){
  17. // var x = 20
  18. // f()
  19. // }
  20. // show(fn) //10
  21. // 测试题2
  22. var fn = function(){
  23. console.log(fn) //输出函数体
  24. }
  25. fn()
  26. var obj = {
  27. fn2:function(){
  28. console.log(fn2) //报错
  29. console.log(this.fn2) //输出函数体
  30. }
  31. }
  32. obj.fn2()
  33. </script>
  34. </body>
  35. </html>