...

View Full Version : What's in a functions argument list anyway?



RadarBob
06-09-2003, 02:44 PM
The called function's argument list has one more argument that passed to it..

When I run the following 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?

mordred
06-09-2003, 03:06 PM
There are only three arguments, the error is in your loop:



for (var i = 0; i <= myObject.arguments.length; i++)


That must be < instead of <=.

RadarBob
06-09-2003, 03:12 PM
:o oops :o
Danke Schone

ahosang
06-10-2003, 12:50 PM
and arguments as a property of Function is deprecated.
So not myObject.arguments, but simply:
arguments within the function definition itself.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum