Apply Method (Function) (JavaScript)

Source: Internet
Author: User

Reprint: Http://msdn.microsoft.com/zh-cn/library/4zc42wh1 (v=vs.94). aspx

Write in front: similar to the call method

Invokes the function and replaces the function's this value with the specified object , replacing the function's arguments with the specified array.

Apply ([Thisobj[,argarray]])

Parameters

Thisobj

Optional. the object to use as the This object.

Argarray

Optional. a set of parameters to pass to the function.

Note

If Argarray is not a valid object, an "expected object" error appears.

If neither Argarray nor Thisobj is provided , the original this object will be used as thisobj and no parameters will be passed.

Example

The following code shows how to use the Apply method.

1 functioncallMe (arg1, arg2) {2Console.log (' This value: ' + This);3    for(varIinchcallme.arguments) {4Console.log (' arguments: ' +Callme.arguments[i])5   }6 }7 8CallMe (1, 2);9 //This value: [Object Window]Ten //arguments:1 One //Arguments:2 A  -Callme.apply (' A ', [' B ', ' C ']) - //This value:a the //arguments:b - //Arguments:c

Requirements

Supported in the following document modes: Quirks, Internet Explorer 6 standard mode, Internet Explorer 7 Standard mode, Internet Explorer 8 standard mode, Internet Explorer 9 standard mode, INT Ernet Explorer 10 Standard mode and Internet Explorer 11 standard mode. In addition, it is also supported in store apps (Windows 8 and Windows Phone 8.1).

Apply Method (Function) (JavaScript)

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.