Re: Array-with-item in WebIDL

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.

Allen

Received on Wednesday, 17 June 2015 15:08:54 UTC