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