Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What's in a functions argument list anyway?

    The called function's argument list has one more argument that passed to it..

    When I run the following code:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    <title>Page title</title>
    
    <script language="JavaScript" type="text/javascript">
    <!--
    function myObject (one, two, three) {
       document.write ("Parameter List:<br>");
    	 document.write ("Number of arguements = " + myObject.arguments.length + "<BR>");
    	 
       for (var i = 0; i <= myObject.arguments.length; i++) {
    	    document.write ("&nbsp;&nbsp;Parameter [" + i + "] = " + 
    			                myObject.arguments[i] + "<br>");
    			document.write ("&nbsp;&nbsp;&nbsp;&nbsp;type = "  +
    			                typeof(myObject.arguments[i])+ "<BR>")
    	 }
    }// myObject()
    //-->
    </script>
    
    </head>
    <body>
    <script language="JavaScript" type="text/javascript">
    <!--
    var one = "one";
    var two =  new String ("two");
    var three = new String ("three");
    
    var thingOne = new myObject (one, two, three);
    document.write ("<BR><BR>");
    //-->
    </script>
    
    
    
    </body>
    </html>
    I get the following output:


    Parameter List:
    Number of arguements = 3
    Parameter [0] = one
    type = string
    Parameter [1] = two
    type = object
    Parameter [2] = three
    type = object
    Parameter [3] = undefined
    type = undefined

    The question
    I passed 3 parameters, but the argument list on the receiving end is 4. Doesn't seem to matter how many arguments I pass, I always have an "extra." What is that last argument?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There are only three arguments, the error is in your loop:

    Code:
     for (var i = 0; i <=  myObject.arguments.length; i++)
    That must be < instead of <=.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oops
    Danke Schone

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Surrey, UK
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and arguments as a property of Function is deprecated.
    So not myObject.arguments, but simply:
    arguments within the function definition itself.


  •  

    Posting Permissions

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