W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2013

Re: Elements (extends Array)

From: Allen Wirfs-Brock <allen@wirfs-brock.com>
Date: Wed, 7 Aug 2013 19:37:25 -0700
Cc: Anne van Kesteren <annevk@annevk.nl>, "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-Id: <B5BD38D6-6ABA-4861-99FC-DF6A10E747BF@wirfs-brock.com>
To: Cameron McCormack <cam@mcc.id.au>

On Aug 7, 2013, at 6:11 PM, Cameron McCormack wrote:

> Anne van Kesteren wrote:
>> For DOM we want to introduce this:
>> https://gist.github.com/domenic/5864658 I.e. an object that's a
>> subclass from Array and can be used in IDL. What do you think the best
>> way forward would be here? Since there's some kind of bridge between
>> IDL and JavaScript it seems we might run into some theoretical
>> problems.
> 
> What are the remaining issues with subclassing Array in ECMAScript, or have they all been solved?  "length" still seems to be handled in a special [[DefineOwnProperty]] for exotic array objects, so just inheriting from Array.prototype won't work.  It also wouldn't test true to Array.isArray.  (Is that a problem?)
> 

The array subclassing issues  have been solved.  See http://wiki.ecmascript.org/lib/exe/fetch.php?id=meetings%3Ameeting_jan_29_2013&cache=cache&media=meetings:subclassing_builtins.pdf In particular the first half of that deck.

When you subclass via the ES6 class declaration (or you can wire it up yourself) it does more than just make the subclass prototype inherit from the superclass prototype.  It also, via the inherited @@create method, causes subclass instances to be allocated in the same manner as the superclass instances.  That means that instances of a subclass of Array are actual exotic array objects.  They use the same [[DefineOwnProperty]] internal method as Array instances and handle the "length" property in the same special way.  Also, Array.isArray answers true for such subclass instances because Array.isArray is actually a test to see if an object is an exotic array object.  Of course, a subclass of Array can explicitly over-ride the inherited @@create method in which case the instance might not allocated as an exotic array object and none of this will be true.

allen
Received on Thursday, 8 August 2013 02:38:00 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:50 UTC