converting arguments to an Array instance

P

Peter Michaux

There seem to be some options for converting the arguments object
inside a function to an instance of Array. I'm curious if anyone has
encountered any problems with any particular techniques for this

From <URL: http://groups.google.com/group/comp.lang.javascript/msg/98c27152ea5c7d55?dmode=source>

var args = [].slice.call(arguments,1);
var args = Array.prototype.slice.call(arguments, 1);

I've tried the following which is short and it seems to work in NN4.08
and O5.02. (I can't seem to keep a stable IE5.5. grrr.)

Array.apply([], arguments)

Thanks,
Peter
 
R

RobG

There seem to be some options for converting the arguments object
inside a function to an instance of Array. I'm curious if anyone has
encountered any problems with any particular techniques for this

From <URL:http://groups.google.com/group/comp.lang.javascript/msg/98c27152ea5c7...>

var args = [].slice.call(arguments,1);
var args = Array.prototype.slice.call(arguments, 1);

I've tried the following which is short and it seems to work in NN4.08
and O5.02. (I can't seem to keep a stable IE5.5. grrr.)

Array.apply([], arguments)

I thought that IE prior to 5.5. didn't have Function.prototype.call or
apply. You may want to implement your own native javascript version
where it is missing.

<URL:
http://groups.google.com.au/group/c...&lnk=gst&q=winter+apply+call#22e0f921fe3043d0
A method that has been discussed before[1] is to augment
Object.prototype with the particular methods you are after, e.g.:

Object.prototype.join = Array.prototype.join;

But that may not be suitable. :)


1. <URL:
http://groups.google.com.au/group/c...guments+array.prototype+robg#bf438840d6b5212e
 
P

Peter Michaux

There seem to be some options for converting the arguments object
inside a function to an instance of Array. I'm curious if anyone has
encountered any problems with any particular techniques for this
var args = [].slice.call(arguments,1);
var args = Array.prototype.slice.call(arguments, 1);
I've tried the following which is short and it seems to work in NN4.08
and O5.02. (I can't seem to keep a stable IE5.5. grrr.)
Array.apply([], arguments)

I thought that IE prior to 5.5. didn't have Function.prototype.call or
apply.

Indeed. I will have to reinstall Windows and IE 5.5 to check IE 5.5's
behavior :-/

It does work in IE6.

You may want to implement your own native javascript version
where it is missing.

<URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thr...



A method that has been discussed before[1] is to augment
Object.prototype with the particular methods you are after, e.g.:

Object.prototype.join = Array.prototype.join;

But that may not be suitable. :)

1. <URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thr...

My eyes are burning!


Peter
 
S

Stevo

Peter said:
Indeed. I will have to reinstall Windows and IE 5.5 to check IE 5.5's
behavior :-/
Peter

No need to. You can use a free Windows image from Microsoft with Virtual
PC. I use VPC and have images for all the OS/IE combinations from
Win95/IE4.0 right up to XP/IE7.
 
S

Stevo

Peter said:
I've tried the following which is short and it seems to work in NN4.08
and O5.02. (I can't seem to keep a stable IE5.5. grrr.)

Again, using VPC helps you keep a stable IE5.5 because you can discard
any Windows updates that might have happened during your session.

I have to wonder why you're putting effort into support NN4.08. That
browser is only going in one direction, and that's down the rankings of
popularity. There can't be more than a couple of thousand people in the
world still using it, and I bet all of them work in the QA departments.
I know of so many major sites (and I deal with a lot of them) that
simply re-route IE4 and NN4 to an unsupported page. You must have a good
bit of code that's unique to NN4 (I remember when I still had to support
it) and that's a very small audience that's demanding it.

It's time the web stopped putting a disproportionate amount of effort in
to support browsers that have < 0.01% market share (that's 1 in 10,000).
We'll only make those people upgrade by grinding them down (if indeed
there are any people outside of QA and automated test-suites still using
it seriously).
 
T

Thomas 'PointedEars' Lahn

RobG said:
Array.apply([], arguments)

I thought that IE prior to 5.5. didn't have Function.prototype.call or
apply. [...]

I can confirm this, and I updated the ECMAScript Support Matrix accordingly:

http://PointedEars.de/es-matrix

Satisfying popular demand, I have modified the style sheet so that the
relation between the rows of each table are more obvious now. Hope you like
it. (If you like the table style of the German computer magazine c't [1], I
have added an alternative stylesheet for that as well.)


PointedEars
___________
[1] http://en.wikipedia.org/wiki/C't
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top