SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    why the output is not arguments

    function args() { return arguments; }
    args();
    the reault is []?what's the "return arguments; meaning?
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    'arguments' holds an array of the arguments given. Any number of arguments can be passed.

    So for example, assuming the above function:
    Code javascript:
    args(1, 2, 3);

    would return an array containing the items 1, 2 and 3.

    Say you have a function:
    Code javascript:
    function countArguments(){
        return arguments.length;
    }

    Then:
    Code javascript:
    alert(countArguments("Hello", "World", "3.14159265358979323846", "Hello again"));

    Would output 4, because 4 arguments are passed to it.

    The function args and countArguments wouldn't have any real-life use, but I suppose its a theory thing. Realistically a function would use the arguments variable in someway, rather than returning it.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •