W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2012

Re: Detecting the "type" of a DOM object

From: Cameron McCormack <cam@mcc.id.au>
Date: Thu, 07 Jun 2012 15:47:44 +1000
Message-ID: <4FD04080.5070707@mcc.id.au>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: "public-script-coord@w3.org" <public-script-coord@w3.org>
Boris Zbarsky:
> So you would be to do something like Node.isInstanceOf(myobj) (or
> something along those lines) and this would return true if myobj is a
> Node, even if it's a Node from a different global.
>
> Thoughts?  This is somewhat similar to the Array.isArray thing ES
> already has...

I think that's a good idea.  If we wanted to follow the Array.isArray 
pattern then we could have Node.isNode, etc., but that might get a bit 
wordy at times (HTMLDivElement.isHTMLDivElement?).

> There are some complications with WebIDL "implements" statements that
> I'm not sure how to deal with, but I think it's pretty rare for people
> to worry about whether something is an instance of the RHS of an
> "implements".

Not sure how useful it is.  They're not counted when you do an 
instanceof currently, either, since that just does the default thing of 
looking up the prototype chain.  The pattern spec writers tend to use 
for interfaces that appear on the RHS of an implements statement is to 
make it [NoInterfaceObject] anyway, unless there's a clear need not to.
Received on Thursday, 7 June 2012 05:48:16 UTC

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