Reference article: blog.crimx.com/2016/05/12/understanding-this/
Notes:
Before the ES6 arrow function This is determined at the time of execution, not when it is defined.
function is called, call when looking for the previous call object, there is a clear display is explicitly displayed object, not remember to look at hidden objects
Functions are also objects, functions can act as properties of an object (this is called a method)
When called as a function, this binds to the global object,
When called as a method, this binds to the object to which the method belongs
1.this in non-strict mode, is the window
In strict mode is undefined
2. The function (or method) in the call, is always the object in the call,
Obvious format, Obj.fun () this is the obj
Stealth format, fun () at this time this is the window, in fact, so Window.fun (), in JS window directly hidden do not write
3. Change This,call and apply with no return value via call and apply
Refer to the "Ye" law (the method of a object to the B object, a object is ye, to write in front), Format Object.prototype.call ()
At this point this is the call/apply first parameter
Call is the same as the Apply function, except that the second parameter is not the same as the form parameter, and the Apply parameter is an array form
4.bind after changing this, the call and apply do not take effect, and bind returns the function that called bind
Bind execution time this point is also the first parameter
5.new a ' class ' (function in JS), this binds to the new object
function Test () {
Console.log (This)
}
The new Test ()//test{} is bound to an empty object first
6. Arrow functions
Where to create this point to WHO
JavaScript this-notes