Javascript Closure

<script type="text/javascript">
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return function(){
return this.name;
};
}
};
console.log(object.getNameFunc()());
name = "The Window";
var object2 = {
name : "My Object",
getNameFunc2 : function(){
var that=this;
return function(){
return that.name;
};
}
};
console.log(object2.getNameFunc2()());
</script>
Stay hungry, stay foolish

浙公网安备 33010602011771号