"Subclassing" basic types in DOM - best method?

Tab Atkins Jr. jackalmage at gmail.com
Tue Nov 20 14:23:21 PST 2012


On Tue, Nov 20, 2012 at 2:02 PM, Rick Waldron <waldron.rick at gmail.com> wrote:
> On Tue, Nov 20, 2012 at 4:52 PM, Tab Atkins Jr. <jackalmage at gmail.com>
> wrote:
>> Of course, that pattern is broken too - it lets you detect actual
>> Arrays, but not things that subclass Array.
>
> That's not possible in JavaScript today, so it's not "broken". There is no
> way to correctly subclass Array, so this has never been an issue that
> JavaScript programs would encounter. Future hostile? Maybe.

function foo() {...}
foo.prototype = [];

You get an object which has a self-updating .length property, gets all
the Array methods like .map(), etc.  If that's not "subclassing", I
don't know what is.  ^_^

~TJ


More information about the es-discuss mailing list