闭包

能够读取其他函数内部变量的函数(定义在一个函数内的函数)

 1 var name = "The Window";
 2 
 3       var object = {
 4         name : "My Object",
 5 
 6         getNameFunc : function(){
 7                 return this.name;
 8     //       return function(){
 9     //         return this.name;
10     //       };
11 
12         }
13 
14       };
15       alert(object.getNameFunc());

 

posted @ 2020-10-15 14:41  小谷要努力!  阅读(99)  评论(0)    收藏  举报