A common judgment of this:
1. function pre-compilation process This -> Window
2. global scope in this -> Window
3.call/apply can change when the function runs this point
4.obj.func (); the This in func () points to obj(that is, who calls the function and this in the function points to whom)
Second, the common use of this:
1. In the custom constructor:
function A () { this. Name = ' a '; this. Age =; }
2. In the function definition of the object, this point points to the object, which can be called within the function by this object's properties.
var obj = { ' lyl ', function () { Console.log (this // lyl } }
3. Define the method on the prototype chain:
function () { // This refers to an array that invokes the method }
4. When JS defines an event:
function () { // This points to the DOM object, $Li this . Style.color = ' red '; }
Three, Strict mode:
ES5 in non-strict mode, this default points to window
ES5 Strict mode, this initial default is undefined, you need to assign a value, and why is the assignment, assignment is Undefined/null is no exception
The this in JS is so magical that I get dizzy.