implicit assignment of this pointer
This always points to the object that called the method;
In the event, This points to the object that triggered the event, and, in particular, the this in theattachevent in IE always points to the Global object Window;
show manipulating this pointer
The JavaScript engine allows us to explicitly specify the object that this pointer refers to in the following two ways:
1. With the new operator, the JavaScript engine returns the this pointer to the assigned variable.
2. By means of function.apply or function.call or function.bind, we can refer to the object of this pointer as an argument, at which point the this pointer used inside the function is the passed in parameter.
the This object in the closure
The This object is bound at run time based on the execution environment of the function: in the global function, this equals window, and when the function is called as a method of an object, this is equal to that object. However, the execution environment of an anonymous function is global , so its this object usually points to window. But sometimes this may not be so obvious because of the way closures are written. Let's look at an example:
var name = "The window" ; var obj = {name: "My obj" function () { return function () { return this .name; }; }}alert (Obj.getnamefunc ()); // "the Window" (in non-strict mode)
The above code first creates a global variable name and creates an object that contains the Name property. This object also contains a method--getnamefunc (), which returns an anonymous function, while
var name = "the window"; var obj = { "My obj", function() { var This ; return function () { return that.name; }; //
In several special cases, the value of this may change unexpectedly. For example, the following code is the result of modifying the previous example:
var name = "the window"; var obj = { "My obj", function() { return this. Name; // ////
The third line of code executes an assignment statement before calling the result after the assignment. Because the value of this assignment expression is the function itself, the value of this cannot be maintained (no reference to obj, the currently active object is window), and the result returns "the window".
Talk about my understanding of this object in JavaScript