The This in JS

Source: Internet
Author: User

1. First analyze the function that this is located as which object is called by method, then the object is the object referenced by this.

2. Through call and apply you can redefine the execution environment of the function, which is the point of this, which is very

Commonly used. The first argument to call and apply is which object the function is called, and this points to the object. Other parameters are bound

The formal parameters of the function. The difference is that call accepts multiple parameters, and apply accepts only two arguments, and the second argument is the binding function's

The array that the formal parameter consists of.

3. The function parameter is not a call to an object, it is a global call, and its this point is a pointer to an object.

4.bind () Function: Take the method out of the object and call it, and you want this to point to the original object when you can

Nice to solve with the bind function.

The target function binds the bind function, this is bound to this in the binding function.

The This in 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.