Array.prototype.slice web-compat issue?

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Sep 10 16:32:32 PDT 2013


On Sep 10, 2013, at 4:11 PM, Andrea Giammarchi wrote:

> Rick I think I've often seen this which is not that naive accordingly with ES 5.1 down to ES 3 specs, IMO .. it worked with DOM, arguments, and everything with a `length` till now.
> 
> ```javascript
> Array.from||(Array.from=function(a){return Array.prototype.slice.call(a)});
> ```
> 
> Allen the `%TypedArray%` is a good example because this is false: `new Float32Array instanceof Array` ... that constructor has even the suffix with the `Array` word but is not an `Array` at all.
> 
> `Array.isArray(new Float32Array)` is again false indeed.
> 
> I also think this magic should somehow be something new, hoping nobody will think about creating polyfills for all Array methods because once again that will be very bad for the web/mobile/ARM world, IMO.

Which magic are you talking about.  Array.isArray is defined for ES6 to test whether an object has the length invariant automatically enforced. That's really the only thing that makes an Array instance special (or in ES6-speak, exotic). Float32Arrays do not have that length invariant because their length is fixed.

What do you think people are actually testing for when they do Array.isArray?  

Allen





More information about the es-discuss mailing list