<script>
//题目一:理解r1与r2的输出
function addFactory(){
var adder = 5;
return function(data){
adder += data;
return adder;
}
}
var adder1 = addFactory();
var r1 = adder1(1);
//console.log(r1);
r1 = adder1(1);
//console.log(r1);
var adder2 = addFactory();
var r2 = adder2(2);
//console.log(r2);
r2 = adder2(2);
//console.log(r2);
//题目二:下面的代码输出什么
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return function(){
return this.name;
};
}
};
alert(object.getNameFunc()());
//题目三:
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
var that = this;
return function(){
return that.name;
};
}
};
//alert(object.getNameFunc()());
</script>