473,809 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ParamArrays in JavaScript functions possible?

Can javascript functions have variable number of arguments - a concept
known as paramarrays?

Apr 18 '06 #1
15 1598
Water Cooler v2 wrote on 18 apr 2006 in comp.lang.javas cript:
Can javascript functions have variable number of arguments
<script type="text/javascript">

function sum() {
var summing = 0;
for(var i = 0; i < sum.arguments.l ength; i++)
summing += sum.arguments[i];
return summing;
}

alert(sum(1,2,3 ,4))

</script>
a concept known as paramarrays?


A rose by any ...
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 18 '06 #2
On 18/04/2006 12:54, Evertjan. wrote:

[snip]
function sum() {
var summing = 0;
for(var i = 0; i < sum.arguments.l ength; i++)

^^^^
The arguments object is a local variable. Referencing it via the
function object is (as I recall) deprecated.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Apr 18 '06 #3
Michael Winter wrote on 18 apr 2006 in comp.lang.javas cript:
On 18/04/2006 12:54, Evertjan. wrote:

[snip]
function sum() {
var summing = 0;
for(var i = 0; i < sum.arguments.l ength; i++)

^^^^
The arguments object is a local variable. Referencing it via the
function object is (as I recall) deprecated.


Could you give a better alternative, please?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 18 '06 #4
Thanks, Evertjan. So, internally, functions are objects, just like in
python. Cool.

....name would smell just as sweet (or, something like that; from Romeo
& Juliet, right?). Thanks!

Apr 18 '06 #5


Evertjan. wrote:

The arguments object is a local variable. Referencing it via the
function object is (as I recall) deprecated.


Could you give a better alternative, please?


You can simply do e.g.
for (var i = 0; i < arguments.lengt h; i++)
in any function to loop through the arguments passed in. Doing
functionName.ar guments
instead of simply
arguments
is deprecated.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 18 '06 #6
Water Cooler v2 wrote on 18 apr 2006 in comp.lang.javas cript:
Thanks, Evertjan. So, internally, functions are objects, just like in
python. Cool.
Objects? I do not think you should conclude this out of my words.
...name would smell just as sweet (or, something like that; from Romeo
& Juliet, right?). Thanks!


Please quote what you are replying to. This is not email but usenet.

If you want to post a followup via groups.google.c om, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsrep ly/>

It seems that sum.arguments is outdated and just arguments works fine.

=============== ===============

However jscript 5.6 specs shows this:

function ArgTest(a, b){
var numargs = arguments.lengt h; //Get number of arguments passed.
var expargs = ArgTest.length; //Get number of arguments expected.
[.....]

.... introducing ArgTest.length as the length of the specified/expected
arguments, new to me!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 18 '06 #7


Water Cooler v2 wrote:
So, internally, functions are objects, just like in
python.


Functions are objects in JavaScript, that is right, but certainly not
only "internally ", whatever "internally " means exactly.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 18 '06 #8
Martin Honnen wrote on 18 apr 2006 in comp.lang.javas cript:
Evertjan. wrote:
The arguments object is a local variable. Referencing it via the
function object is (as I recall) deprecated.

Could you give a better alternative, please?


You can simply do e.g.
for (var i = 0; i < arguments.lengt h; i++)
in any function to loop through the arguments passed in. Doing
functionName.ar guments
instead of simply
arguments
is deprecated.


Thanks, see my other post for functionName.le ngth.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 18 '06 #9
>Please quote what you are replying to. This is not email but usenet.

huh?

a concept known as paramarrays?
A rose by any ...

Thanks, anyways.

Apr 18 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1019
by: Avis | last post by:
Hi, Iam trying to convert a VB6.0 class library in which I have implemented byref paramarrays for pulling the values back to the caller method: A sample method is given bellow: public function getFields(sForm as string, paramarray Fields() as variant) I would use this method as follows:
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.