JavaScript Arguments objects

Source: Internet
Author: User

1. In JavaScript, the arguments object is a more specific object, which is actually a built-in property of the current function. Arguments is very similar to an array, but is not actually an array instance. Can be confirmed by the following code (of course, in the function Funcarg, the call arguments is not necessarily written funcarg.arguments, write arguments directly).

1 ARRAY.PROTOTYPE.TESTARG = "Test"; 2 function Funcarg () {3 alert (FUNCARG.ARGUMENTS.TESTARG); 4 alert (Funcarg.arguments[0]); 5}6 7 alert (new Array (). Testarg);                Result: "Test" 8 Funcarg (10); Result: "Undefined" "10"

2. The length of the arguments object is determined by the number of arguments and not by the number of parameters. A parameter is a variable inside a function that re-opens the memory space, but it does not overlap with the arguments object memory space. In the case of arguments and values, the values are synchronous, but for one of the none, the value of this no value is not synchronized. The following code can be verified.

 1 function f (a, b, c) { 2     alert (arguments.length);    // result:  "2"  3     a = 100; 4      alert (Arguments[0]);       // result:  " " 5     arguments[0] = " Qqyumidi "; 6      alert (a);                   // result:  "Qqyumidi"  7     alert (c);                   // result :  "undefined"  8     c = 2012; 9      alert (arguments[2]);       // result:  "undefined" 10 } 11 12 f (1, 2); 

3, the function in JavaScript, the Declaration and invocation of features, you can see that the JavaScript function is not overloaded.

Depending on the overloads in other languages: "The return value of the function is different or the number of formal parameters is different", we can draw the above conclusion:

First: The declaration of a JavaScript function is not a return value type;

Second: The number of formal parameters in JavaScript is strictly in order to facilitate the manipulation of variables in the function, and the actual arguments are already stored in the arguments object.

In addition, the JavaScript function itself is a deep understanding of why a function in JavaScript cannot be overloaded: in JavaScript, a function is actually an object, a function name is a reference to a function, or the function name itself is a variable. For function declarations and function expressions as shown below, it is very useful to understand that a function in JavaScript cannot be overloaded without considering the difference between a function declaration and a function expression.

1 function f (a) {2 return a + 3} 4 5 function f (a) {6 return a-10; 7} 8 9//without considering the difference between a function declaration and a function expression, it is equivalent to the following Ten-one var f = function (a) {return a + 10;13}14 var f = function (a) {a-10;17}

4. There is a very useful attribute in the arguments object: callee. Arguments.callee returns the current function reference where this arguments object resides. It is recommended to use Arguments.callee instead of the function name itself when using recursive function calls.

As follows:

1 function count (a) {2 if (a==1) {3 return 1;4} 5 return a + Arguments.callee (--a); 6}7 8 var mm = Count (ten); 9 alert (mm);

JavaScript Arguments objects

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: 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.