The understanding of this JS

Source: Internet
Author: User

Points for one or four different modes of minor

1. When the function calls the mode, this points to the window

2. When the method invokes the pattern, this points to the object where the method is located

3. In the constructor mode, this points to the newly generated instance

When 4.apply/call invokes a pattern, this points to the first parameter in the Apply/call method

The most used should be 2 and 3, in JS Object-based programming, these two should be the most common

Ii. Apply and call

1. Use of apply and call

All functions contain both methods, and you can assume that the apply and call methods force the this within a function to point to an object.

2. Difference between apply and call

The difference between apply and call is only the this reference within the called function (method), which refers to the object being passed as the first parameter of the Apply/call. and the difference between apply and call is how they are passed on to other parameters.

The understanding of this JS

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.