A supplement to the This keyword in JS

Source: Internet
Author: User

Front:

Although the front of the network, though a lot of Daniel's experience, but the feeling still do not do, in order to thoroughly understand the JS in this knowledge, decided to write another article. Personally, technically, unless you drill into the details, it is difficult to reach a very high level.

Supplement 1:

This cannot be overridden because it is a keyword.

Supplement 2:

Pasting

$ ( function   ()   {$ ( ' button ' ). Click (function   ()   {alert (this ); //this represents native Dom  $ (this)  ;  //represents the current object, this refers to button }) })
This indicates that the current context object is an HTML DOM object that can invoke properties owned by an HTML object, method. $ (this), which represents the context object that is a jquery context object that can invoke the methods and property values of jquery.


Supplement 3:

The point of this is not deterministic at the time of the function definition, only when the function is executed can you determine who the this is pointing to, in fact this is the object that called it , and there are some problems with this sentence. Although most of the articles on the internet say so, although in many cases to understand that there will be no problem, but in fact, that understanding is inaccurate.

Supplement 4:

Alert is also a property of window, which is also a window point. For example, the alert (this) is executed in the window environment and the result is:

[Object Window]

About the addition of this keyword in JS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.