码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript:说看懂了就懂了闭包,看懂了,还是不懂...

时间:2015-01-28 17:35:53      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

<script>
var name = "The Window";
var setter;
var object = {
  name : "My Object",
  getNameFunc : function(){
    return function(){
      return this.name;
    };

  }

};
alert(object.getNameFunc()());

function t(){
setter=function (){name = "My Object";};
function b(){alert(this.name);}
return b;
}
var object1=t();
object1();
setter();
object1();


function out()
{
name = "My Object";
function inner()
{
alert(this.name);
}
return inner;
}

var result=out();
result();
</script>

JavaScript:说看懂了就懂了闭包,看懂了,还是不懂...

标签:

原文地址:http://www.cnblogs.com/architects/p/4256086.html

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