473,404 Members | 2,170 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,404 software developers and data experts.

Wierd call on methods

JS
I read the following in som sample code:

function createOpts(sel){
var s = new Array();
var num = 0, txt = "bo";
var ar = opt = null;
var n = sel.selectedIndex;
var args = createOpts.arguments.length;
....
....
....
....

The createOpts method that a select object as argument. Creates a new Array:

When no argument is specified for an Array I guess its just empty with size
1.

The line that says:

var args = createOpts.arguments.length;

Is it correct that args holds the number of options that the selectobject
contains??

Jul 23 '05 #1
2 1206
JS wrote:
I read the following in som sample code:

function createOpts(sel){
var s = new Array();
var num = 0, txt = "bo";
var ar = opt = null;
var n = sel.selectedIndex;
var args = createOpts.arguments.length;
....
....
....
....

The createOpts method that a select object as argument. Creates a new Array:

When no argument is specified for an Array I guess its just empty with size
1.
Its empty with a length of 0. Arrays have no "size" property.
The line that says:

var args = createOpts.arguments.length;

Is it correct that args holds the number of options that the selectobject
contains??


No, args contains a number that relates to the length of a possible list
of arguments passed to a function.

try this in your browser:

function checkArguments(args){
alert(checkArguments.arguments.length)
}

checkArguments(1);
checkArguments(1,2);
checkArguments(1,"2","string");

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2
On 26/05/2005 23:25, JS wrote:

[snip]
var args = createOpts.arguments.length;
This should be

var args = arguments.length;

The arguments object should be accessed directly, not via a function object.
Is it correct that args holds the number of options that the selectobject
contains??


No. The arguments object represents the arguments passed to a function
when it's called. It will look like an array, but it isn't: it only has
two named properties, length and callee, and a series of numbered
properties starting at zero (0). For example,

/* Declaration */
function myFunction(arg0, arg1) {}

/* Call */
myFunction('string', 15, false);

The function, myFunction, is called with three arguments, but there are
only two named (or formal) arguments in the declaration. So, how do we
access the third? Using the arguments object.

In this example, arguments will have five properties in total:

arguments[0] The value of the first argument (arg0): 'string'
arguments[1] ...of the second argument (arg1): 15
arguments[2] ...of the third (it has no name): false
arguments.length The number of arguments passed to the function: 3
arguments.callee A reference to the function, myFunction, itself.

Does that make sense?

Presumably, createOpts allows any number of extra arguments after the
first one, sel. These extra arguments will probably be the display text
and values for the new OPTION elements. Rather than creating a long,
pointless list like

function createOpts(sel, text1, value1, text2, value2, ...) {}

which become almost impossible to work with, it just takes the extra
arguments from the arguments object.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

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

Similar topics

2
by: Florian Lindner | last post by:
Hello, I've this code: print "Login1:", login login.replace("@","_") print "Login2:", login Which produces this output: Login1: tester@root
3
by: Niloday | last post by:
Hi All, I have developed a web service and deployed it on the Win2000 box. I can access the web methods of this web service when my client application is debugged from VS.NET studio. But it...
1
by: paul reed | last post by:
Hello, I am having some weird behavior between two machines...one which is running the 1.1 framework and one which is running 1.0. After opening a child form from a parent...I update the...
5
by: desktop | last post by:
I am confused about the use of the template parameter "E" in the below class. Since when is it allowed to use these parameters like "E(1)" and what does it mean (where can I read more about this...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.