The usage of this keyword in JavaScript is detailed in Object-Oriented Programming Languages and we are very familiar with this keyword. For example, C ++, C #, and Java all provide this keyword. Although it is difficult to start learning, you only need to understand it, it is very convenient and meaningful to use. JavaScript also provides this keyword, but it is much more "messy" than the classic OO language.
Let's take a look at the confusion in the use of this in JavaScript?
1. Use the this keyword in the inline mode of HTML element event attributes:
Pision element
A common method is to use the following format: audio cirpt: EventHandler (this. However, you can write any legal JavaScript statement here. If you are happy to define a class here, You can (but it will be an internal class ). The principle here is that the script engine generates an anonymous member method for the p instance object, and onclick points to this method.
2. Use the this keyword in the event processing function in DOM mode:
The Code is as follows:
Pision element