Array.prototype.slice web-compat issue?

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Sep 10 12:45:48 PDT 2013


My main concern was about non `Array` objects such instances of `Arguments`
or `NodeList` or others Array_ish_ instances where to work with `.slice()`
all we need is a `length` property.

If these will return not as `instanceof` current `Array` realm most of the
code will be broken.

If `.slice()` will be that smart as I expect, I wonder why nobody is
mentioning `.concat()` as able to concatenate every Array_ish_ and produce
an `instanceof` the original object constructor that invoked that concat
call.

`ArrayIsh.prototype.concat([]) instanceof ArrayIsh`

Last doubt would be about `Array.isArray` and the inability to distinguish,
if not via `Object#toString` or `instanceof` between two different
`ArrayIsh` objects ... so that `instanceof` will be not usable for
`ArrayIsh` and at the same time the best solution to understand what kind
of `ArrayIsh` it is so that extra, enriched, methods can be used.

Thoughts?




On Tue, Sep 10, 2013 at 12:25 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com>wrote:

>
> On Sep 10, 2013, at 11:12 AM, Andrea Giammarchi wrote:
>
> > As short answer, let me reformulate:
> > AFAIK 99% of libraries out there believe that slice.call will return an
> Array, no matter which realm. In ES6 I see there's too much magic involved
> because of subclassing possibility.
>
> Presumably this is a 100% reasonable expectation today, because that's
> that the ES<=5.1 specs say.  However, often do they depend upon the value
> being a direct instance of Array as opposed to being an instance of a
> subclass of an array, assuming that the subclass how all the observable
> characteristics of an Array instances including answering true to
> Array.isArray and maintaining the Array invariant.
>
> In other words, those libraries have never encountered a true subclass of
> Array.  When they do, is anything bad going to happen if the result object
> is also a subclass of Array?
>
> BTW, I think it is useful to distinguish this use case from applying slice
> to non Array.isArray objects or using slice as a strange way to create a
> new Array instance.
>
> Allen
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130910/ebf4c023/attachment.html>


More information about the es-discuss mailing list