typeof null

Brendan Eich brendan at mozilla.org
Wed May 9 16:25:34 PDT 2012


Axel Rauschmayer wrote:
> It would be great if we could eliminate these predicates completely. 
> How often does the frame crossing problem matter in practice? It 
> doesn’t show up in non-browser environments, right?

Those matter but not so much. I know, Node.js -- I'm a fan. But really, 
we have a large user base that does, I'm told, often enough face the 
problem that !(someArrayFromAnotherWindow instanceof Array).

> I see several possibilities:
> - Make instanceof work correctly with objects that have crossed frames.

We can't do this. It will break code that knows how instanceof works -- 
by walking the prototype chain. There's no magic here, either, unless 
you want this cross-frame equivalence to apply only to built-ins, based 
on some internal nominal tag (such as the identiy of the code pointer 
for the two frames' Array constructors).

> - Introduce a binary predicate, e.g. likeInstanceOf that correctly 
> handles cases where the lhs and rhs come from different contexts/frames.

Again, how? The name of the constructor in one frame may not be relevant 
in the other. The constructor may not be a built-in. Are you thinking in 
nominal type terms again? :-/

> Additionally, one could throw an exception if there is an instanceof 
> check whose lhs and rhs are from different contexts (failing fast, 
> preventing obscure and hard-to-debug errors).
This too would be an incompatible change. I don't see any upside in 
messing with instanceof, and it has its uses (if only in Node.js :-).

/be


More information about the es-discuss mailing list