Javascript-function/arguments

Source: Internet
Author: User

Description:

Create a new function.

Syntax:

      1. Function funname ([argu1 [, argu2 [,... [, Argun]) {}
      2. VaR funname = function ([argu1 [, argu2 [,... [, Argun]) {}

Funname is essential.

Example:

Example Effect
Function add (x, y ){ReturnX + Y;} document. Write (add (1, 2 ));
3
VaR add =NewFunction ("X","Y","Return x + y"); Document. Write (add (1, 2 ));
3

 

Attribute:

Attribute Description
Arguments Returns an arguments object for the currently executed function object.
Caller Returns a reference to the function that calls the current function.

 

 

Arguments:

The arguments object cannot be displayed. The arguments object is only available at the beginning of the function.

The arguments object of the function is not an array, but it can be accessed using subscript like an array.

Attribute Description
[I] I: required.
Returns the value of the I parameter.
Syntax:
Arguments [I]
Length Returns the number of parameters of the function.
Syntax:
Arguments. Length
Callee Returns the function object being executed.

Example:

Example Effect
Function CILS (x, y) {document. Write ("ARGs:"+ Arguments. Length +"<Br/>");For(VAR I = 0; I <arguments. length; I ++) {document. Write ("ARGs ["+ I +"] ="+ Arguments [I] +"<Br/>") ;}} CILS );
Function add (x ){If(X = 1 ){Return1 ;}Else{ReturnX + arguments. callee (x-1);} document. Write (add (100 ));
Related Article

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.