The arguments of JavaScript

Source: Internet
Author: User

Javascrip China each function will have a arguments object instance arguments, which references the arguments to the function, and can refer to the arguments element in the form of an array subscript "[]". Arguments.length is the number of function arguments, and Arguments.callee refers to the function itself.

Arguments his features and how to use them

Characteristics:

Arguments objects and function are inseparable. Because the arguments object cannot be created explicitly, the arguments object is available only when the function is started.

How to use:

Although the arguments object is not an array, accessing a single parameter is the same way you access an array element

For example:

arguments [0],arguments[1],。。。。。。。。 arguments [N],

In JS, you do not need to explicitly specify the parameter names, you can access them, for example:

function Test () {        var s = "";          for (var i = 0; i < arguments.length; i++) {            alert (arguments[i]);             + = Arguments[i] + ","        ;        } return s;    } Test ("name", "Age")

Output Result:

Name,age

Let's take a look at the Callee property and return theFunctionObject
function  the body of the object. The callee   property is a member of the   arguments  object and is available only if the related function is executing.
< Span class= "pun" >< span class= "str" >< Span class= "PLN" >< Span class= "PLN" > callee   The initial value of the property is the   that is being executed; function  object, which allows anonymous recursive functions.

var function (n) {        if (1 = = N)            {return 1;         Else {            return n + arguments.callee (n-1);        }    }    Alert (SUM (6));

Output Result:

21st

The popular point is that arguments This object is used mostly for multiple calls to the same method and for different number of passes. According to < Span class= "pun" >< span class= "str" >< Span class= "PLN" >< Span class= "PLN" > arguments index to determine the method of execution

JavaScript arguments

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.