Javascript notes and summaries (1-3) arguments

Source: Internet
Author: User

Arguments is the argument list (object) when the function is run, each function has its own arguments, but does not look for the related properties of the arguments in the outer function, that is not the chain (only OA forms the scope chain).

Example 1

<script>(function(d, E, f) {    console.log (arguments);    Console.log (typeof  arguments);}) (' JavaScript ', ' Programming ', '! ') ); </script>

Output in console

["JavaScript", "Programming", "!" ]object

Example 2 arguments collects all the arguments, even if there are no corresponding formal parameters

<script>(function(d, E, f) {    console.log (arguments);}) (' JavaScript ', ' Programming ', '! ', ' node '); </script>

Output in console

["JavaScript", "Programming", "!", "Node"]

When a function is run, the variables that can be referenced inside the function are ①ao②arguments③this

Example 3-shape participation corresponds to a arguments unit that is mapped to each other

<script>(function(d, E, f) {    Console.log (arguments[0]);    arguments[0] = ' backbone ';    Console.log (d);}) (' JavaScript ', ' Programming ', '! ', ' node '); </script>

Output in console

Javascriptbackbone

Example 4 arguments gets the number of arguments when the function is run

<script>(function(d, E, f) {    console.log (arguments.length);}) (' JavaScript ', ' Programming ', '! ') ); </script>

Console output: 3

Functions that are currently running on the "Arguments.callee property"

Example 5

<script>(function(d, E, f) {    console.log (Arguments.callee);}) (' JavaScript ', ' Programming ', '! ') ); </script>

Console output:

function (d, E, f) {    console.log (Arguments.callee);}

Example 6

Use recursive summation

<script>function  t (n) {    if(n<=1) {        return  n;    }  Else{        return n + t (n-1);    }} Console.log (t ()); </script>

Output: 5050

Recursion is now done using anonymous functions

<script>Console.log (    (function  (n) {        if(n<=1) {             return  n;        } Else {            return n + arguments.callee (n-1);        }    }) (+)); </script>

Output: 5050

Javascript notes and summaries (1-3) arguments

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.