1, in JavaScript, the execution code must be placed in the function, if not shown in the Write function, the code is automatically placed in a member function of window;
2, JavaScript functions are member functions, must belong to an object, if the object is not displayed, then this function belongs to the Window object;
3, JavaScript functions are executed in three ways, one is called as a member function, when the function body of this point to the object of the function, and the second is called as a constructor, this time the function body of this point to the newly created object through this constructor; , the This in the function body is controlled by the parameter.
4, this point and the syntax of the definition function is independent of the location, only related to the way the function was called.
The above is the text from the summary section of copy in http://www.2cto.com/kf/201208/149899.html. For beginners JS I like Newton found the new continent =
--------------------------------------------------------------------------------------------------------------- ---------------------
First, all JS execution code into the function, if there is no explicit function, it will automatically be placed in a window member function
All JS codes are grouped into functions, and then the functions are grouped into objects. JS all functions are member functions, all must belong to an object. If not, it belongs to the Window object.
Eg:document.write ("xxx"); ---> Function x (xx) {document.write ("xxx");} ---> Window () {x (XX)}
After all the normalization is complete, the context of this can be well discussed.
The first thing to make clear is that the execution context of this is determined during the run, and that it is determined at the time of definition.
And then the above said, one is called as a member function, when the function body of this point to the object of the function, and the second is called as a constructor, the function body of this point to the new object through this constructor, and the third is called through apply or call, The this in the function body is controlled by the parameter.
Above 2016-01-10 14:55:39
In JavaScript, this usage is detailed