SEO Forums: Your seo discussion forum  
Welcome, Unregistered.
You last visited: Today at 10:54 PM
Tags:



Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-25-2008, 04:55 AM
oldyork90
Guest
 
Posts: n/a
Default functions and arguments.length; passing unknown number of arguments



I'm going thru code and have never seen this before
http://www.webreference.com/programm...column2/3.html


Look at function CreateDragContainer() on line 25. It has no
arguments defined and depends on a function property named arguments
to process its input. I poked around and found this is deprecated.

How do you pass an unknown number of arguments to a function? Put
them in an array?

Thanks.
Reply With Quote


  #2 (permalink)  
Old 09-25-2008, 04:55 AM
Joost Diepenmaat
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number of arguments

oldyork90 <oldyork90@yahoo.com> writes:

> I'm going thru code and have never seen this before
> http://www.webreference.com/programm...column2/3.html
>
>
> Look at function CreateDragContainer() on line 25. It has no
> arguments defined and depends on a function property named arguments
> to process its input. I poked around and found this is deprecated.


Function.arguments is deprecated. The automically instantiated variable
arguments is not.

> How do you pass an unknown number of arguments to a function? Put
> them in an array?


I use the arguments variable.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Reply With Quote


  #3 (permalink)  
Old 09-25-2008, 04:55 AM
SAM
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number of arguments

Le 9/24/08 9:23 PM, oldyork90 a écrit :
>
> How do you pass an unknown number of arguments to a function? Put
> them in an array?


function hello() {
for(var i=0; i< arguments.length; i++) alert(arguments[i]);
}

hello('hello guy');
hello('hello','old boy');
hello('hello','Old Rock','the 90th');

var t1 = 'Hello';
var t2 = 'man';
hello(t1, t2);


Is there really necessary to put previously the arguments in an array ?


var or = ['hello','Old Rock','the 90th'];

function salut() {
arguments = arguments.length==1?
arguments[0].toString().split(',') : arguments;
for(var i=0; i< arguments.length; i++) alert(arguments[i]);
}

salut(or);

--
sm
Reply With Quote


  #4 (permalink)  
Old 09-25-2008, 03:54 PM
Kiran Makam
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number ofarguments

On Sep 25, 12:23 am, oldyork90 <oldyor...@yahoo.com> wrote:

> How do you pass an unknown number of arguments to a function? Put
> them in an array?


You can use an object (with necessary properties initialized) to pass
the arguments.
For example, if your function requires 5 arguments: arg1, arg2...arg5

function myFn(oArgs){
var arg1 = oArgs.arg1;

//initialize if the arg is not passed
var arg2 = (oArgs.arg2 == undefined)? "myDefaultValue" : oArgs.arg2;
}

//function call
myFn(
{
arg1: "xxx",
arg2: "yyy",
...
arg5: "zzz"
}
);

- Kiran Makam

Reply With Quote


  #5 (permalink)  
Old 09-26-2008, 08:31 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number of arguments

Joost Diepenmaat wrote:
> Function.arguments is deprecated. The automically instantiated variable
> arguments is not.
>
>> How do you pass an unknown number of arguments to a function? Put
>> them in an array?

>
> I use the arguments variable.


`arguments' is a property of the Activation/Variable Object of a local
execution context, but not a variable. And no, that is not a contradiction


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
Reply With Quote


  #6 (permalink)  
Old 09-27-2008, 07:23 AM
Joost Diepenmaat
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number of arguments

Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:

> Joost Diepenmaat wrote:
>> Function.arguments is deprecated. The automically instantiated variable
>> arguments is not.
>>
>>> How do you pass an unknown number of arguments to a function? Put
>>> them in an array?

>>
>> I use the arguments variable.

>
> `arguments' is a property of the Activation/Variable Object of a local
> execution context, but not a variable. And no, that is not a contradiction


In the interest of academics; is there any way to tell the difference
using javascript code?

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Reply With Quote


  #7 (permalink)  
Old 09-27-2008, 07:23 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number of arguments

Joost Diepenmaat wrote:
> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>> Joost Diepenmaat wrote:
>>> Function.arguments is deprecated. The automically instantiated variable
>>> arguments is not.
>>>
>>>> How do you pass an unknown number of arguments to a function? Put
>>>> them in an array?
>>> I use the arguments variable.

>> `arguments' is a property of the Activation/Variable Object of a local
>> execution context, but not a variable. And no, that is not a contradiction

>
> In the interest of academics; is there any way to tell the difference
> using javascript code?


Quick hack for testing if `x' was declared a local variable:

/\bvar\s+([A-Za-z_$][\w$]*\s*,\s*)*x\b/.test(arguments.callee)

This should be adapted for Unicode-aware implementations, see ES3F 12.2 and
7.5.3.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
Reply With Quote


  #8 (permalink)  
Old 09-27-2008, 07:23 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number of arguments

Thomas 'PointedEars' Lahn wrote:
> Quick hack for testing if `x' was declared a local variable:
>
> /\bvar\s+([A-Za-z_$][\w$]*\s*,\s*)*x\b/.test(arguments.callee)
>
> This should be adapted for Unicode-aware implementations, see ES3F 12.2 and
> 7.5.3.

^^^^^
I meant the following section, 7.6 ("Identifiers"), of course.

Thank you and good night ;-)


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Reply With Quote


  #9 (permalink)  
Old 09-27-2008, 07:23 AM
Jorge
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number ofarguments

On Sep 27, 1:12*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> Joost Diepenmaat wrote:
> > Thomas 'PointedEars' Lahn <PointedE...@web.de> writes:
> >> Joost Diepenmaat wrote:
> >>> Function.arguments is deprecated. The automically instantiated variable
> >>> arguments is not.

>
> >>>> How do you pass an unknown number of arguments to a function? *Put
> >>>> them in an array?
> >>> I use the arguments variable.
> >> `arguments' is a property of the Activation/Variable Object of a local
> >> execution context, but not a variable. *And no, that is not a contradiction

>
> > In the interest of academics; is there any way to tell the difference
> > using javascript code?

>
> Quick hack for testing if `x' was declared a local variable:
>
> * /\bvar\s+([A-Za-z_$][\w$]*\s*,\s*)*x\b/.test(arguments.callee)
>


Parsing the source ? come on ! That's not serious !

Try to see a bit further than your own nose. Activation objects are
notional entities. They could as well have called them 'magically
bound variables'.

--
Jorge.

Reply With Quote


  #10 (permalink)  
Old 09-27-2008, 07:24 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: functions and arguments.length; passing unknown number of arguments

Jorge wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Joost Diepenmaat wrote:
>>> Thomas 'PointedEars' Lahn <PointedE...@web.de> writes:
>>>> Joost Diepenmaat wrote:
>>>>> Function.arguments is deprecated. The automically instantiated variable
>>>>> arguments is not.
>>>>>> How do you pass an unknown number of arguments to a function? Put
>>>>>> them in an array?
>>>>> I use the arguments variable.
>>>> `arguments' is a property of the Activation/Variable Object of a local
>>>> execution context, but not a variable. And no, that is not a contradiction
>>> In the interest of academics; is there any way to tell the difference
>>> using javascript code?

>> Quick hack for testing if `x' was declared a local variable:
>>
>> /\bvar\s+([A-Za-z_$][\w$]*\s*,\s*)*x\b/.test(arguments.callee)

>
> Parsing the source ? come on ! That's not serious !


If you have a better idea, then post it. If not, shut up.

> Try to see a bit further than your own nose. Activation objects are
> notional entities.


Whatever you might mean by "notional", Activation Objects exist and are part
of the scope chain of function code (ES3F, 10.2.3). Furthermore, "The
activation object is then used as the variable object for the purposes of
variable instantiation." (10.1.6) Unfortunately, the Activation/Variable
Object cannot be referred to, hence this quick hack.

> They could as well have called them 'magically bound variables'.


You could as well be called an incompetent fool, but I will assume in your
favor you are just tired or drunk or both right now. So go to bed, please.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
Reply With Quote


Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:54 PM.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Great Seo Blog at SEONOTEPAD.COM