473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 4250
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tony | last post by:
When writing a function that takes in a variable number of parameters and processing it using func_get_args or a similar technique, I'm assuming that one is only able to use the pass by value...
8
by: Rico Huijbers | last post by:
Hello, I'd like to know if it's possible to curry a function in PHP? That is, is there some built-in mechanism for it, or is it possible to create a function that does the currying? I've...
2
by: Martijn | last post by:
Hi, I have to write a dynamic page which has to run on several platforms, using different databases. Because of that, I want to write a small db-front-end which is an almost 1-on-1 mapping of...
16
by: micha | last post by:
i have the following code: function some_function($argument) { validate_arg(); //more code } function validate_arg() {
3
by: Curtis | last post by:
Hello everyone: Recently, I've come across the need to accept an arbitrary amount of arguments in my function, but I also need to alter the data in the calling scope. I have been trying to...
8
by: Razzbar | last post by:
I've been trying to write a general buffer function that looks something like this: function buffer($arg){ ob_start(); $arg; return ob_get_clean(); } Note that the intention is for this to...
15
by: Mikhail Kovalev | last post by:
Hi all, I have a file which is to be included in another script and which takes several seconds to load(!), and which is actually not always used by the script, so instead of using include or...
10
by: Matthew | last post by:
Am I correct in thinking there is no method/function overloading of any kind in any version of PHP? Thanks, Matthew
0
by: Csaba Gabor | last post by:
Between Dec 16, 2005 and May 31, 2006 a significant change occurred in one aspect of how php (version 5.1 on Win XP) arguments are handled. Consider the following script which changed behaviour in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.