Explore JavaScript----This pointing problem

Source: Internet
Author: User

The *this is only relevant to the execution environment and is independent of the declaration environment. Whoever calls This,this is pointing to WHO.

*this's point is divided into four types:

1. As a normal function call:

   

2. Method invocation as an object:

Points to the object, but when the method is referenced with a new variable, it becomes a normal function call, pointing to window:

   

Explanation: The method is actually an object, the attribute assigns a function, and the O.GETN represents this function, assigns it to a new variable call, becomes the ordinary function call.

3. In the constructor, point to the instance object computed by the new operator.

4.apply Call:

The function of apply is to change the calling object of the function, whose first parameter represents the changed calling object, so this point points to the first parameter.

* The global function is called by default when the argument to apply is null or NULL.

* Sometimes we use call and apply for the purpose of not specifying the point of this, but rather the method of borrowing other objects, then we pass NULL instead of a specific object.

Math.max.apply (null,[1,2,33,4,6]);//33

Explore JavaScript----This pointing problem

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.