The difference between this in js and java
this in js
this refers neither to the function itself nor to the lexical scope of the function. It would be too easy to mislead if you only use the English explanation of this. It actually binds when the function is called. That is to say, what this points to depends on how you call the function. That is, whoever calls the function, this will point to .
This points to window by default, if the function is called directly.
this in java
When the local (or formal parameter) variable and the member variable have the same name, use this in the method to represent the member variable with Show distinction.
If you call another method of the same class inside the method, you do not need to use this. Similarly, if there are no local variables and member variables with the same name in a method, then there is no need to use this
1 and to indicate a reference to the current object when using member variables in this method!
2. Indicates using class member variables instead of function parameters. 3. Used to reference the constructor that satisfies the specified parameter type in the constructor (actually, it is also the constructor). But you must be very careful here: only one constructor can be referenced and it must be at the beginning! 4. Obviously this cannot be used in static methods, because this refers to the current object, and static has no object. php Chinese website, a large number of freeJava introductory tutorials, welcome to learn online!
The above is the detailed content of The difference between js this and java. For more information, please follow other related articles on the PHP Chinese website!