On Dec 23, 7:23 am, Jon Kleiser <jon.klei...@usit.uio.no> wrote: > Hi, > > I'm using prototype-1.6.0.3.js, and I'm trying to subclass Array like this: > > var MyArr = Class.create(Array, { > initialize: function($super, arg) { $super(arg); } > > }); > > Or just like this: > var MyArr = Class.create(Array, {}); > > Neither seems to work at all. In the Firefox Error Console I get > "Error: parent.subclasses is undefined" with a reference to line 62 > in the prototype file. > Is it possible to subclass Array?
That would depend on what you mean by "subclass an Array". Prototype's `Class.create` uses quite popular `clone`/`beget` inheritance pattern. While such pattern allows to actually create an Array "subclass" (i.e. a constructor function that creates objects with `Array.prototype` somewhere in their prototype chain) any such object is doomed to be missing some of the traits of native array objects - i.e. index properties' manipulation does not affect `length` property and vice versa. What were you planning to use this "subclass" for? > > /Jon -- kangax --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---