RE: Solving the "how do I tell whether I have an HTML element?" (or image element, or whatever) problem

> From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU]
> The proposal is that the expression "x instanceof Foo" where "Foo" is a
> WebIDL interface object for a non-callback interface as defined at
> http://dev.w3.org/2006/webapi/WebIDL/#interface-object will return true if
> and only "x" is a platform object implementing the relevant interface.
> 
> So "x instanceof Element" would be true if x is an Element, no matter what
> its owner document is.

I don't think that's quite what you want. For multiple documents inside of a single window instance this is already true:

var d1 = document.implementation.createHTMLDocument("text/html");
var t1 = d1.createElement("table");
var t0 = document.createElement("table");
t0 instanceof HTMLTableElement
> true
t1 instanceof HTMLTableElement
> true
t0.ownerDocument === t1.ownerDocument
> false
(The above is IE10 current behavior)

I think you are asking that when comparing instances of elements originating from two different window objects the instanceof check can return true.

Will this be new ECMAScript 6 behavior for instanceof, or will this require some new operator/method? (I may have missed this earlier in the thread...)

Received on Thursday, 17 January 2013 21:49:38 UTC