function box () {
return arguments[0] + ' | ' + arguments[1];
}
Alert (Box (1, 2, 3, 4, 5, 6));
Output: 1|2
Description: 1 ECMAScript function does not mind passing in the number of parameters, nor because the parameters are not uniform and error. As a matter of fact
The body of the function can receive the passed in parameters through the arguments object.
2 The Length property of the arguments object can be used to get the number of arguments.
Expand:
We can use the length of this property, to intelligently determine how many parameters, and then the parameters of the rational application.
For example, to implement an addition operation, all incoming numbers are added, and the number is indeterminate.
function box () {
var sum = 0;
if (Arguments.length = = 0) return sum;
If there are no parameters, exit
for (var i = 0;i < Arguments.length; i++) {
If you have one, accumulate it.
sum = sum + arguments[i];
}
return sum;
Returns the cumulative result
}
Alert (Box (5,9,12));
js function parameter Arguments[0]