Cross-global instanceof

David Bruant bruant.d at
Thu Oct 31 08:50:40 PDT 2013

Le 31/10/2013 16:38, Anne van Kesteren a écrit :
> This keeps coming up. Last instance:
> We have it for Array using Array.isArray().
Array.isArray is not at all equivalent to instanceof. Not even related.
     Object.create(Array.prototype) instanceof Array === true

     var a = [];
     a.__proto__ = null;
     Array.isArray(a) === true;

We need both types of checks, one for "is such object in the prototype 
chain?" and the other for "how is this object magic?" (Array, Date, 
WeakMap, File, whatev's). The source code you're linking to seems to 
want the latter.

> It is unclear why the
> arguments for arrays not apply to other types of objects, such as
> array buffers, nodes, blobs, files, etc.
> We could introduce something like
>    Object.crossGlobalInstanceOf(instance, type)
> which checks @@crossGlobalBrand or some such which works for built-ins
> and is also usable by jQuery and the like.
I'm not sure it's worth making it work for jQuery. This is trying to 
make a good use of same-origin multi-global which shouldn't exist in the 
first place. Keeping same-origin access as it is and encouraging people 
to add @sandbox even on same-origin iframes seems like a better idea.

Should the addition be a nicer


More information about the es-discuss mailing list