Apply and call

Source: Internet
Author: User

1. Overview

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 in the function class
Params: This is a list of parameters

(has not understood, changed the context scope, now understand, this point)

2, the understanding of apply and call,

is to bind the attribute method inside the function to obj, Because the context is changed, so the t inside the function His will point to obj (this property will produce some advanced usage)

3. Difference between apply and call

is to pass the parameters in a different way, you think,function inside will accept parameters , when obj inherits the function, then the function has parameters, then

and pass it over from there? So only arguments, think so, I sometimes want a whole piece (array) pass through (apply), and sometimes want to preach (call)

4,Some special ways to use apply

Because apply can pass an array (), then it can be Math.max.apply (Null,[paramn]);

Apply and call

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.