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

Re: Array-with-item in WebIDL

From: Allen Wirfs-Brock <allen@wirfs-brock.com>
Date: Wed, 17 Jun 2015 08:08:28 -0700
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>
Message-Id: <9ECFC3CE-ADF3-4D25-873D-C36172B68190@wirfs-brock.com>
To: Jonas Sicking <jonas@sicking.cc>

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

This archive was generated by hypermail 2.3.1 : Wednesday, 17 June 2015 15:08:54 UTC