Stack and ArrayObject - How to create an advanced subclassed Array constructor
Another problem left to solve is that after subclassing an Array one would like the return types of Array.prototype methods to be of the subclass type instead of its superclass type Array. This comment is, basically, a summary of the reason I created the ArrayObject constructor . Today, I have totally rewrote that constructor, using a Stack instance as prototype. The Stack constructor aim is to subclass the Array one in the most compatible, and light, way. For this reason, I have not changed native Array behaviours, those that return an Array, for example, instead of a Stack instance (concat, filter, map, slice). But the good thing of Stack, is that now we can create our subclassed Array constructor, without affecting the native Array object, and adding, modifying, or removing, whatever we want. For example, to solve the problem described on top of this post, I have simply modified inherited Stack methods, returning an instance of ArrayObject , every time we use, for example, a conca...