469,343 Members | 5,380 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

A function like PHP's func_get_args?

Hi,

I need a function that takes not-fixed number of arguments. There is a
perfect solution at PHP (func_get_args) but I could not find an
alternative for JavaScript.

reference:
http://php.net/manual/en/function.func-get-args.php
http://php.net/manual/en/function.func-num-args.php
http://php.net/manual/en/function.func-get-arg.php

Apr 7 '06 #1
3 4071
I think I found what I need. Check it out:
http://wp.netscape.com/eng/mozilla/3..._a-c.htm#42839

Apr 7 '06 #2
ce****@gmail.com said on 07/04/2006 1:02 PM AEST:
I think I found what I need. Check it out:
http://wp.netscape.com/eng/mozilla/3..._a-c.htm#42839


That documentation is old, it appears to be targeted at Navigator 3
which was first released in about 1994.

The arguments object is not an array, it is a list. It is like an array
as it has properties that can be referenced by index and it has a length
equal to the number of arguments provided to the function. But it
doesn't have any of an array's special methods like join, concat, pop,
and so on.

Do not prefix 'arguments' with the function name, just call it with
'arguments':

function someFunc()
{
for (var i=0, len=arguments.length; i<len; ++i)
{
alert( 'Argument ' + i + ': ' + arguments[i] );
}
}

someFunc('arg0', 'arg1', 'arg2');
An 'arguments' object is also created for anonymous objects where it can
be accessed exactly as above:

var aFunc = function()
{
for (var i=0, len=arguments.length; i<len; ++i)
{
alert( 'Argument ' + i + ': ' + arguments[i] );
}
}

aFunc('A', 'B', 'C');


--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Apr 7 '06 #3
RobG wrote:
[...]

An 'arguments' object is also created for anonymous objects where it can


Agghh, anonymous *function*, of course.


--
Rob
Apr 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tony | last post: by
8 posts views Thread by Rico Huijbers | last post: by
2 posts views Thread by Martijn | last post: by
16 posts views Thread by micha | last post: by
8 posts views Thread by Razzbar | last post: by
15 posts views Thread by Mikhail Kovalev | last post: by
10 posts views Thread by Matthew | last post: by
reply views Thread by Csaba Gabor | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.