Re: Array-with-item in WebIDL

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