Array extensions
Way back when, I wrote a library to extend the Array object to use with Internet Explorer 5.0, which still didn’t include the ECMAScript 3rd edition methods. I had also defined several other functions I found useful. Recently, I found this file and decided to update it with the new Mozilla methods. So, if you’re so inclined, take a look at the zArray library.
Update: I really wish I had noticed that Erik had already done something similar…really could’ve saved me the time. Oh well.
Update 2: Erik correctly pointed out that my implementation of every() was faulty. I have fixed it and updated zArray to version 1.01.
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.
Both comments and pings are currently closed.




7 Comments
I thought you blogged about this when I released that? Well, yours works without call which will help non ECMAScript edition 3 compatible engines.
Didn't you forget the object argument to every?
Erik Arvidsson on August 1st, 2005 at 6:44 pm
Yeah, I did blog about it when you posted it. But I have this thing about reading blogs…I never follow the links while I'm reading because I get too distracted. I thought that the link you had was to source for your own methods, not for an emulation of the Mozilla methods. It was only after I stopped by again and clicked that I saw the Mozilla ones as well.
When I originally wrote this library oh so long ago, I wrote it to incorporate splice(), push(), pop(), shift(), and unshift() into non-ECMAScript 3rd edition browsers, so I figured I'd just keep the trend alive with this one.
You're right, the every() method is messed up. Gotta fix that. Thanks for pointing that out.
Nicholas C. Zakas on August 1st, 2005 at 7:52 pm
Your implementation of every seems to return false for a zero-length array… There's a mozilla bug report about this behaviour, https://bugzilla.mozilla.org/show_bug.cgi?id=305002, so mozilla will probably change to true for calling every on an empty array.
(looks like Erik's implementation returns true for an empty array)
christian biesinger on August 17th, 2005 at 9:10 pm
Thanks for pointing that out, Christian. I'll take a look.
Nicholas C. Zakas on August 18th, 2005 at 10:52 am
It seems the link (http://www.nczonline.net/downloads/zArray1.0.zip) is broken. It gives 404 Not found
Bruce Weirdan on September 9th, 2005 at 7:52 am
Yes, the filename changed with the version number. You should always go directly to the download page and not rely on direct URLs to the zip file.
Nicholas C. Zakas on September 9th, 2005 at 1:07 pm
Nicholas, I think you should point out that this will brake named arrays. I also extended the Array object in a project (only the indexOf method) and this turned out to be a major headache.
Problem is this, you do a for each loop in your named array and it will also inlcude all the attached methods:
var aObjects = [];
aObjects["myObj"] = {};
aObjects["myOtherObj"] = {};
for(var i in aObjects)
{
alert(i + " = " + aObjects[i]);
}
José Jeria on April 29th, 2006 at 11:19 am
Comments are automatically closed after 14 days.