The Parameter object arguments in a JavaScript function is an object, not an array. But it can be like an array to access the elements in the following table, and it also has a length property that identifies the number of its elements.
Validating the parameters of a function using the arguments object is legitimate
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 The 25 26 |
<script> function sum (ARG1,ARG2)//addition function {var realargcount = arguments.length;//The number of arguments passed when calling a function var frmargcount = sum. Length The number of parameters in the function definition if (Realargcount < Frmargcount)//If the number of actual arguments is less than the number of parameter {var e = new error ();//define error message, then throw e.number = 1000001;/ /error Number E.message = "The number of actual parameters does not meet the requirements!" "///error message throw e;} return arguments[0] + arguments[1];//parameter to match the request extracts the arguments from the arguments object and returns both the and} try {document.write ("<p> |
The above mentioned is the entire content of this article, I hope you can enjoy.