1.Arguments
Arguments.length is the number of function arguments, andArguments.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]); s + = Arguments[i] + ","; } return s;} Test ("Name", "age") output result: Name,age
We know that each object has its own properties, and the arguments object is no exception, first arguments access is like an array object, with 0 to arguments.length-1 to enumerate each element.
Let's take a look at the callee property, which returns the function object being executed, which is the body of the specified function object. The Callee property is a member of the arguments object and is available only if the related function is executing.
The initial value of the Callee property is the function object being executed, which allows anonymous recursive functions.
var sum = function (n) { if (1 = = N) { return 1; } else { return n + arguments.callee (n-1)} } Alert (SUM (6)); 21 = 6 + 5 + 4 + 3 + 2 + 1
The popular point is thatarguments this object is used mostly for multiple calls to the same method and for different numbers of arguments. The method of execution is judged according to the index of the arguments.
2. Call
.
3.Apply
.
Function of arguments, call, apply