JS 闭包

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title></title>
 6     </head>
 7     <body>
 8     </body>
 9     <script type="text/javascript">
10     //一个函数运行结束以后它里面所有的变量会被编译器所收回
11     //简单的理解闭包:函数的嵌套
12         function fun1(){
13             var num1 = 10;
14                 function fun2()
15                     num1++;
16                      console.log(num1);
17                     return num1;
18                 }
19                 //var result = fun2;
20                 //return result;
21                 return  fun2();
22         }
23         fun1();
24     </script>
25 </html>
26 </html>

 

posted @ 2016-05-31 19:06  PowellZhao  阅读(101)  评论(0编辑  收藏  举报