Javascript's hidden object arguments

Source: Internet
Author: User

Arguments is an object similar to an array but not an array. It is similar to an array because it has the same access nature and method as an array, you can use arguments [N] to access the values of a single parameter and have the Length attribute of the array length.
In addition, the arguments object stores the parameters actually passed to the function,
It is not limited to the list of parameters defined in the function declaration,
You cannot create an arguments object explicitly. The arguments object is available only when the function starts.

Instance
Function argtest (A, B)
{
VaR S = "parameter defined by the argtest method = ";
VaR S1 = "parameters passed in by the argtest method = ";
VaR numargs = arguments. length; // obtain the value of the passed parameter.

VaR expargs = argtest. length;

S + = expargs
S + = "<br>"
S1 + = numargs
S1 + = "<br>"
For (VAR I = 0; I <numargs; I ++)
{// Obtain the parameter content.
S1 + = "Arg" + I + "=" + arguments [I] + "/N ";
}
Document. Write (S + "<br>" + S1)
}

Argtest (3 );

Note: function. Length returns the number of parameters defined by the method.

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.