js中this关键字的使用

<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>
上一篇:referer htttp headers 统计信息 防盗链


下一篇:软件项目技术点(7)——在canvas上绘制自定义图形