Home > Java > JavaBase > The difference between js this and java

The difference between js this and java

angryTom
Release: 2019-11-14 11:14:46
Original
2591 people have browsed it

The difference between js this and java

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 free

Java 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template