---restore content starts---
This point
1, this points to the object that is bound when the function is called. When there is no bound object, point to Windows
2, in the browser, the global environment of this point to the Windows object.
3, can change the point of this through call/apply, ES5 can change the point of this by bind
function person () {
this.name = ' person ';
this.msg = function (msg) {
msg = MSG | | THIS.name;
Alert (msg);
}
}
function Cat () {
THIS.name = ' cat ';
}
var p = new person ();
var c = new Cat ();
P.msg.call (c, ' one ', ');//cat
4, the arrow function of this, define where, then point to where
function person () {
this.name = ' person ';
this.msg = function (msg) {
msg = MSG | | THIS.name;
Alert (msg);
}
This.init = function () {
Document.onclick = () =>{
Console.log (this);
Under normal circumstances this should point to the document, but at this point it points to the person object
}
}
}
P.init ();
---restore content ends---
This in JavaScript points to