JavaScript--作用域链

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6     <script>
 7         var a = 10;
 8 
 9         function fn() {
10             var b = 20;
11             function fn1() {
12                 var c = 30;
13                 console.log(a + b + c); // 60
14             }
15 
16             function fn2() {
17                 var d = 40;
18                 console.log(c + d); // 找不到c,会报错
19             }
20 
21             fn1();
22             fn2();
23 
24         }
25         fn();
26 
27     </script>
28 </head>
29 <body>
30 
31 </body>
32 </html>

作用域链图:

 

 

posted @ 2017-10-30 15:48  QinXiao.Shou  阅读(148)  评论(0编辑  收藏  举报