W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2013

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

From: Tom Van Cutsem <tomvc.be@gmail.com>
Date: Thu, 24 Jan 2013 09:22:54 +0100
Message-ID: <CAKDfNj-sr6Ftd8gNeXjYT2azmULvTPPKR6ht-eOKXOm5xy+vhA@mail.gmail.com>
To: Cameron McCormack <cam@mcc.id.au>
Cc: Travis Leithead <travis.leithead@microsoft.com>, Boris Zbarsky <bzbarsky@mit.edu>, "public-script-coord@w3.org" <public-script-coord@w3.org>, es-discuss <es-discuss@mozilla.org>
2013/1/24 Cameron McCormack <cam@mcc.id.au>

> 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

Cheers,
Tom
Received on Thursday, 24 January 2013 08:23:21 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:08 UTC