Arguments learning in Javascript

Source: Internet
Author: User

Arguments is a parameter of the currently executing function that holds the arguments that are currently called by the functions. How to use: function.arguments[i]. where function. is an option and is the name of the function that is currently executing. Arguments cannot be created, it is a parameter of the function itself and can only be used if the function starts execution. Although the use of arguments is much like an array, it is not an array. Here's a demonstration with an example:
function Argumentstest (A, b) {        alert (typeof arguments);} (argumentstest);

As you can see, this is the browser window that pops up, and the arguments type is object.

function Argumentstest (A, b) {        //alert (typeof arguments);        alert (arguments.length);} (argumentstest);
Popup results:
function Argumentstest (A, b) {        //alert (typeof arguments);        alert (arguments.length);        Alert (arguments[1]);} (argumentstest);
Popup Result: Note The following code:
function Argumentstest (A, b) {    //alert (typeof arguments);    alert (arguments.length);    Alert (arguments[1]);} Argumentstest (1,2,3,4);
Popup Result: The result of the popup is 4. Here is the callee method, which returns the function object that is being executed.
function Argumentstest (A, b) {    //alert (typeof arguments);    alert (arguments.length);    Alert (arguments[1]);    alert (Arguments.callee);    alert (arguments.callee.length);} Argumentstest (1,2,3,4);
Popup Result: The following is the key, arguments.callee.length return how much?
function Argumentstest (A, b) {    //alert (typeof arguments);    alert (arguments.length);    Alert (arguments[1]);    alert (Arguments.callee);    alert (arguments.callee.length);} Argumentstest (1,2,3,4);
Popup Result: Arguments.length Returns the length of the argument, 4 , and Arguments.callee.length returned is the length of the formal parameters, only for 2.2013.8.30 today and encountered arguments, found that there are a few points to master is particularly clear. 1. First, arguments is a built-in parameter to the function object. It is a function/method in the execution process, consisting of an object passed in by the parameters, the system built-in, can be called. is independent of the arguments at the time of the function declaration (when a function declaration is not declared, it does not affect the use of arguments). 2. The overloads can be simulated according to the arguments. Specific can be seen here: http://www.w3school.com.cn/js/pro_js_functions_arguments_object.asp

Arguments learning in Javascript

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.