首页 > 代码库 > JavaScript:说看懂了就懂了闭包,看懂了,还是不懂...

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>

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