Skip to Content

NCZOnline

Blog Entry

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.

Comments

Erik Arvidsson says:

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?

Nicholas C. Zakas says:

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.

christian biesinger says:

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)

Nicholas C. Zakas says:

Thanks for pointing that out, Christian. I'll take a look.

Bruce Weirdan says:

It seems the link (http://www.nczonline.net/downloads/zArray1.0.zip) is broken. It gives 404 Not found

Nicholas C. Zakas says:

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.

José Jeria says:

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]);
}

No further comments allowed for this posting.

Copyright © 2004-2005 Nicholas C. Zakas. All Rights Reserved. XHTML | CSS