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