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

Tom Van Cutsem at
Thu Jan 24 00:22:54 PST 2013

2013/1/24 Cameron McCormack <cam at>

> On 18/01/13 9:09 AM, Travis Leithead wrote:
>> I think this sounds fine. Most web developers don't expect the
>> current spec'd behavior, even though to me it seems more natural.
>> IE has the current behavior and I expect we would migrate to the new
>> behavior at some point once it was defined and agreed upon.
> At one point a long time ago, Web IDL did require [[HasInstance]] to be
> overridden to return true even for objects from different windows.  If
> proxies now support trapping that, I'll just add it back.

Just to clarify: we've previously talked about proxies trapping
[[HasInstance]], but instead settled on an approach that does not require
proxies (see below).

> I guess this will change to the @hasInstance that Allen mentions, once ES6
> stabilises and I actually understand what "@hasInstance" means. :)

@hasInstance denotes a unique symbol. If a JavaScript object (any object,
doesn't have to be a proxy) defines a property with that symbol as a key,
it will be able to intercept instanceof. My understanding of how this would
work is roughly as follows:

// get the hasInstance symbol from somewhere (e.g. import from a std module)
var hasInstance = ...;

function Foo() {...};
Foo[hasInstance] = function(subject) { return <boolean-expression>; }

obj instanceof Foo // calls the above function, passing obj as the subject

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list