Arguments
The object represents the function being executed and the arguments that call his function.
Arguments property: Returns arguments objects and parameters for Function objects in the current execution.
[function.] Arguments[n]
Parameter description:
Parameter function: option. The name of the Function object that is currently executing.
N: Indicates the passed-over parameter subscript index
1. For Parameter objects
Description: Arguments is a hidden object created in addition to the specified arguments when a function call is made.
<script>var result =function () { alert (arguments.length); Returns 2
Alert (argument[0]); //Return to 123};result (123,'nihjao') ; </script>
It is known that in the absence of the definition of formal parameter variables, love, also passed over the parameters, and was arguments accepted. So arguments is a hidden object
Defining formal parameter acceptance parameters in a function
var result =function (y) { alert (y); alert (result.arguments[0]); Returns 123 alert (arguments[1]); Returns Nihao alert (arguments.length); Returns 2 arguments.length refers to the argument length alert (arguments.callee.length); Return 1 Arguments.callee.length is the formal parameter length};result (123,'nihjao') ; </script>
At this point: the function defines a parameter y to accept the passed argument, only accept the first one.
2.callee property returns the function object being executed
Returns the function object being executed, which is the body of the specified function object.
function Calleedemo () { alert (Arguments.callee);}
Callee can print the function itself
The callee property is a member of the arguments object, and he says a reference to the function object itself , which facilitates the recursion of anonymous functions or ensures the encapsulation of functions that are available only when the function is executing
Note: callee has the length property, Arguments.length is the actual parameter, and the arguments.callee.length is the length of the formal parameter, thus determining whether the parameter length in the call is consistent with the argument length.
recursive calculation : The sum of the natural numbers of 1 to n is calculated recursively?
varsum =function (n) {if(N <=0)return 1; Else returnn +Arguments.callee (n-1 )} more general recursive functions:varsum =function (n) {if(1==n)return 1; Else returnn + sum (n1);} When called: Sum ( -);
Where the function contains a reference to the sum itself, the function name is just a variable name, call sum inside the function is equivalent to calling a global variable, does not well reflect the call itself, when using callee will be a better method.
JS's arguments attribute interpretation function parameter?