W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2015

Re: Array-with-item in WebIDL

From: Jonas Sicking <jonas@sicking.cc>
Date: Wed, 17 Jun 2015 10:39:17 -0700
Message-ID: <CA+c2ei_7yiDFrtrtmu3uW6cr_PBtaExBp66wPHJH7oOvCuxREw@mail.gmail.com>
To: Allen Wirfs-Brock <allen@wirfs-brock.com>
Cc: Travis Leithead <travis.leithead@microsoft.com>, Joshua Bell <jsbell@google.com>, "Tab Atkins Jr." <jackalmage@gmail.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>
On Wed, Jun 17, 2015 at 8:08 AM, Allen Wirfs-Brock
<allen@wirfs-brock.com> wrote:
>
> On Jun 16, 2015, at 3:59 PM, Jonas Sicking wrote:
>
>>
>> I'd also love to hear some thoughts about what we want Array.isArray()
>> to return for one of these objects. And would using a subclass of
>> Array accomplish that desired behavior?
>
> Generally, in ES6, Array.isArray will return true when applied to instances of subclasses of Array.
>
> More specifically, Array.isArray returns true for any object that implement the 'length' property semantics of Array instances (roughly, adding an element past the current length cases the value of the 'length' t property to increase).  By default, instances of Array subclass have this characteristic but it is possible to define an Array subclass that does not.  Similarly, it is possible to defined a class that does not inherit from Array but whose instances still have that characteristic.  Also, note that Array.isArray works on cross-realm objects.
>
> It would be trivial to define a subclass of Array (WebIDLArray?, ItemArray?, whatever...) that added 'contains' and 'item' properties.  That class could then be further subclassed, if desired. Array.isArray would answer true when applied to instances of those subclasses.

Cool. So I take it that that means that we'd want Array.isArray to
return true for these objects, and that we'd accomplish that by using
an Array subclass. Sounds great to me!

/ Jonas
Received on Wednesday, 17 June 2015 17:40:19 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 17 June 2015 17:40:20 UTC