In object-oriented programming language, 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 off... SyntaxHighlighter. all ();
In object-oriented programming language, 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:
Js Code
// You can use this
"> Division element
// You can use this
"> Division elements are commonly used here in the form of 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 div instance object, and onclick points to this method.
2. Use the this keyword in the event processing function in DOM mode:
Js Code
Division element