JAVA / JS regarding this and that

- JAVA in on this and that
 this pit, this is the nature of the problem appears pointers and they want not the same.
 with this type of context is directly related to the executable code, when entering the value of this execution context is determined, and the permanent change operation during execution context.

Uncover the mystery of this & that - http://www.sohu.com/a/158143999_505825
 the this in the end what value? The value of this is dynamic, is when the function is called to perform really determined, when the function definition can not be determined. Because this is part of the value of the execution context, each function call, will have a new execution context. this role is used to specify the execution context in which the object context is triggered.
 Since this is the execution context is determined, then classify the types of execution context can be divided into three kinds: So then we execute a global context from the Global ExecuTIon Context, FuncTIon ExecuTIon Context function execution context, Eval Execution Context Eval execution context this three categories

- JS of this and that
 this refers to the current object. that is a temporary variable that holds the current object of this state. (That can easily name).
Page ({
  Data: {
  },
  the onLoad: function () {
    var = that the this;
    this.a =. 1;
    the console.log (this.a)
    the setTimeout (function () {
      the console.log (this.a)
      the console.log (that.a)
    }, 1000)
  }
})
Rationale :( has three log, I referred to that log1, Iog2, log3 the)
that log1 print 1, herein this refers to a value of the object function onLoad.
Iog2 printed result is undefined, where this is an anonymous function object setTimeout inside, it is not of a.
log3 print out 1, where a value that represents the onLoad function object.

$ ( '# conten') the Click (function () {.
      // the this is clicked #conten
      var = that the this;
      . $ ( '. conten') each (function () {
          // the this cycle is .conten the current object
          // that is still just clicked my #conten
      })
  })

In javascript, this represents the current object. var that = this is to copy the current variable that this object.
$ ( '# zhetenga') the Click (function () {. 
  // the this is clicked #zhetenga 
  var = that the this;
  . $ ( '. zhetenga') each (function () {
     // the this cycle is .zhetenga the current object 
     // that is still just clicked #zhetenga 
  }); 
}); 
you can see, this will be subject to change at any time in the program, but after var that = this, that did not change until the time of this point is still so it will not appear in the original object was not found.

Guess you like

Origin blog.csdn.net/ShareUs/article/details/90738615