JavaScript:说看懂了就懂了闭包,看懂了,还是不懂...
<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>
posted on 2015-01-28 15:51 JAVA小书童<bj> 阅读(73) 评论(0) 编辑 收藏 举报