js this 闭包

时间:2021-10-17 15:37:00
var myObject = {
  value :,
  increment:function (inc){
    this.value += typeof inc ==='number' ? inc:;
  }
};
myObject .increment();
console.log(myObject.value);
myObject .increment();
console.log(myObject.value); var a=;
var b={
a:,
c:function(){
console.log(this.a);
}
}
b.c();
(b.c)();
(,b.c)(); function f1(){
    var n=;
    nAdd=function(){n+=}
console.log(n);
    function f2(){
      alert(n);
    }
    return f2;
  }
var result=f1();
result();
nAdd();
result(); 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()());