PDA

View Full Version : Subclassing Array Object in IE?


jBrennan
12-05-2005, 07:14 PM
The code below creates a subclass of Array called "AddressCollection" and then definies a class method "loadFromDocument". The loadFromDocument method looks for <UL> elements with the name attribute set to "address" and then extracts some expected information from it's children <LI> tags and adds that information to a new custom object named "address". All of this works fine. I then attempt to use the .push() function to append the newly created Address object to the AddressCollection. This works fine in Firefox, but IE6 ignores it.

Any suggestions or tips are greatly appreciated.

Thanks,
James

AddressCollection.prototype = new Array();
AddressCollection.prototype.constructor = AddressCollection;
AddressCollection.superclass = Array.prototype;
function AddressCollection(){}

AddressCollection.prototype.loadFromDocument = function() {
var addr = document.getElementsByName("address");
for(var i=0;i<addr.length;i++) {
var li = addr[i].getElementsByTagName("li");
var a = new Address(
addr[i],
li["name"].firstChild.nodeValue,
li["street"].firstChild.nodeValue,
li["city"].firstChild.nodeValue,
li["state"].firstChild.nodeValue,
li["zip"].firstChild.nodeValue
)
this.push(a);
}
}