Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function arguments

Status
Not open for further replies.

linusSanto

Programmer
Jul 31, 2003
15
IN
If the formal and actual argument of function
(i mean arguments in function defination and function declaration )
should match in numbers and the data type then how in the javascript if i call any function i can use
function xyz()
{
var argv = xyz.arguments;
..........
}

How in this case it does not look for the arguments it passes from the function call?
 
>> If the formal and actual argument of function
(i mean arguments in function defination and function declaration )
should match in numbers and the data type...


You are basing this on a false supposition that the number and datatype of arguments must be identical in both the function declaration and function call. This is not the case. Firstly, the datatype of an argument is only determined by what is passed to the function. Secondly, if more or less arguments than defined are passed, the function will still execute, either ignoring extraneous arguments or reporting missing arguments as 'undefined'.

You can use [tt]var argv = xyz.arguments;[/tt] on any function. In fact, if you need to make sure a specific number of arguments were supplied, or do something different depending on the number of arguments it's a very good idea.
 
Linus,

You call a JavaScript function the same way most other language function cals are made. Functions return a value of some sort.

So, say you had a function called AverageHeight, and it was well-written, you could call it like this:

Code:
var AverageHeightOfMyChickens
AverageHeightOfMyChickens = AverageHeight(12.4,94,6.8);

Just like that.

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Edward,

Help me out here for a second..

you put this in..

var AverageHeightOfMyChickens
AverageHeightOfMyChickens = AverageHeight(12.4,94,6.8);


I understand what you are doing here.. was that a typo on the example or is it correct as it stands?

var AverageHeightOfMyChickens;
AverageHeightOfMyChickens = AverageHeight(12.4,94,6.8);

Thanks,

Brian
 
sdi,

javascript is forgiving of trailing semicolons (unfortunately, imho)

you can use them or leave them off in most cases. a carriage return will be interpreted as end of statement.

i always use them though...good practice.



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Hi Brian,

Yep, that was a typo on my part. JavaScript lines should all end in semi-colons, unless there is an explicit reason for them not to. Mea culpa!

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top