Arguments object validation function argument is legitimate

Source: Internet
Author: User
Tags function definition

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.