JS call () and apply () understand

Source: Internet
Author: User

1. Call () and apply () Effect:Because JS does not have the concept of private class, we often use these two methods to implement your component when we do the component development, understand this also can help to understand the value of JS "This" (is part of execution context) 2.call () and apply () Source: Call () and apply () is the member method of function (), and other methods are obtained by inheriting the function () through the "--proto--" (implicit prototype).

3.call () and apply () difference: essentially something is the same, the only difference is that the arguments are not the same function.apply (Obj,args) method can receive two parameters obj: This object will replace the This object in the Function class Args: This is an array, which is passed as a parameter to Function (args-->arguments) function.call (obj,[param1[,param2[,... [, Paramn]]] OBJ: This object will replace the This object params in the function class: This is a parameter list 4. Usage Understanding: 4.1 Apply automatically converts a parameter array to a list of parameters that are passed to a method, and your own existing data is an array of parameters, It can be handled conveniently by this time. Eg: Gets the maximum and minimum values in the array: 4.2 Change method The this scope of the class part

JS call () and apply () understand

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.