Essay (i): The object in the JavaScript function----arguments

Source: Internet
Author: User

About arguments

When calling a function, if you need to pass a parameter, the argument is an array, which can be accessed by the built-in object arguments of the function body, such as:

ARGUMENTS[0]: first parameter

ARGUMENTS[1]: Second parameter

ARGUMENTS[2]: Third parameter

ARGUMENTS[3]: Fourth parameter

Of course, in the name of the function, you can also do not need to name parameters, call arguments directly, such as:

Use the Length property in arguments to know the number of parameters passed in:

A function can pass in different parameters, so that the method can be overloaded in JavaScript by means of a parameter.

       function test () {            var len=arguments.length;            Switch (len) {case                0:alert ("This is a method without parameters");                Case 1:alert ("This is a method of 1 parameters");                Case 2:alert ("This is a method of 2 parameters");                Default:break;            }        }        Test ();                                           This is a method with no parameters        test ("I am the first parameter");                             This is a method of 1 parameters        test ("I am the first parameter", "I am the two parameter");              This is a method of 2 parameters

  

Essay (i): The object in the JavaScript function----arguments

Related Article

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.