(1) use this in the Global execution environment to identify the Global object, which is the window object in the browser.
(2) when this is used in the function execution environment, if the function does not explicitly act as an attribute of a non-window object, but only defines the function, whether this function is defined in another function or not, this in this function still identifies the window object. If the function is displayed as a non-window object attribute, this in the function indicates this object.
Copy codeThe Code is as follows:
Var o = new Object;
O. func = function ()
{
Alert (this = o ));
(Function (){
Alert (this = window ));
}
)();
}
O. func ();
(3) When a function is called using the new operator, the function is treated as a constructor. this points to the object created by the constructor.
For more details, refer
Javascript this pointer