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.
Long story: Historically, `instanceof` has been cross browser/engine the fastest way to understand if an object is an Array, compared with both `Object#toString.call(arr)` and/or `Array.isArray` plus the web does not really pass Arrays between iframes anymore thanks to `postMessage` and other serialization mechanisms where, once deserialized, `instanceof` will do the trick (also JSON.parse creates Arrays of the current realm) Caja is a very-very-very specific use case that does not reflect majority of websites so `instanceof` worked most of the time for most of the site but regardless, Caja believes slice.call wil generate an `Array` that will be `instanceof Array` and this is a valid assumption for every sandboxed code that believes in `instanceof` rejecting all external "unknown" instances. Finally, `Object.prototype.toString.call(object)` instead of `instanceof` is abusing a hack that is also slow ... subclassing is not only about `Array` .. or is it? 'cause in such case I'd rather suggest a new constructor called `ArrayLike` or `ArrayObject`, easier to polyfill and ready to be subclassed with all the needed magic (as reflection of `Array` behavior) Off Topic: I've personally tried to subclass Array since IE5 so this is a welcome thing but does not seem to be that practical as specced now considering existing code. On Tue, Sep 10, 2013 at 10:46 AM, Allen Wirfs-Brock <al...@wirfs-brock.com>wrote: > > On Sep 10, 2013, at 10:37 AM, Andrea Giammarchi wrote: > > > AFAIK 99% of libraries out there believe that slice.call will return an > Array of the current realm. > > Can you explain why the Realm makes a difference to them? Is it because > they are doing instanceof Array tests rather than Array.isArray? > > Allen > > >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss