码迷,mamicode.com
首页 > 其他好文 > 详细

闭包练习

时间:2016-11-08 01:14:19      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:foo   log   on()   img   nbsp   setname   alert   this   common   

 var name = "window"; 2 var foo = { 3             name: "hello", 4             setName:function(){ 5                 return function(){ 6                     return this.name; 7                 }; 8             } 9         }; 10         alert(foo.setName()());  11 // window

技术分享
技术分享
 1 var name = "window";
 2         var foo = {
 3             name: "hello",
 4             setName:function(){
 5                 var that = this;
 6                 return function(){
 7                     return that.name;
 8                 };
 9             }
10         };
11         alert(foo.setName()());
12 //hello

闭包练习

标签:foo   log   on()   img   nbsp   setname   alert   this   common   

原文地址:http://www.cnblogs.com/chun6/p/6040893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!