javascript闭包特性

http://www.cnblogs.com/rubylouvre/archive/2009/07/24/1530074.html

 

 

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

 

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

 

 

posted @ 2014-04-20 12:17  daishuguang  阅读(123)  评论(0编辑  收藏  举报