Subj : Re: Array and [ ] To : netscape.public.mozilla.jseng From : Jens Thiele Date : Mon Jan 24 2005 12:31 am Brendan Eich schrieb: > although a subclass of Array might be more appropriate in a real application what exactly do you mean with subclass here? js2? the only way i know to inherit from objects like Array (or in fact to inherit [[class]] involves __proto__). Example: // "hack" for inheriting [[class]] function assert(f) { if (!f()) throw "Assertion failed:"+f.toSource(); } function Subarray() { var ret=Array(); ret.__proto__=Subarray.prototype; return ret; } Subarray.prototype.foo=function(){return this.length;} Subarray.prototype.__proto__=Array.prototype; s=Subarray(); s[0]=s[1]=10; print(s.foo()); assert(function(){return s.foo()==2;}); assert(function(){return s instanceof Subarray;}); assert(function(){return s instanceof Array;}); though I in fact like this i also could imagine js without new and without .prototype only having __proto__. I think this would make it more obvious how the prototyping works and stop the confusion and wrong expectations. Greetings jens .