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: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Wed, 16 Jan 2013 13:14:07 -0800
Message-ID: <CABZUbM3LbzUW+t9=Y-SVor_YUK7YPfae7UtCUzdRutyDM+zMwQ@mail.gmail.com>
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: public-script-coord@w3.org, es-discuss <es-discuss@mozilla.org>
On 1/16/13, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> On 12/31/12 11:33 PM, Boris Zbarsky wrote:
>> 1)  Hack instanceof as Gecko has in the past.  This is actually a bit of
>> a pain to implement even in Gecko, without changes to SpiderMonkey,
>> because function objects can't have the magic behavior the RHS needs
>> above in SpiderMonkey at the moment.
> We have decided to go this route in Gecko, I believe, given that Allen
> says this will be describable in ES6.
> In the short term that means that our WebIDL interface objects will
> probably not be function objects but reasonable facsimiles.  In the
> longer term we'll probably add a way to have functions have custom
> instanceof behavior to SpiderMonkey.
I understand the idea of making instanceof less wacky apnd hacky. Is
there room for a non-normative warning"don't do that" warning in the
spec? Because otherwise, it'll be on stackoverflow and blogs as:

Q: How do I know if my object is an element?
A: Use instanceof if (x instanceof Element)

Where instanceof instanceof might seem generally more reliable.

I think it's a good idea to put a warning somewhere (WebIDL?) about
compatibility problems and API versions, such as:

Using instanceof to determine Object type is not strongly reliable
across APIs, API versions, browser manufacturer discrepencies, and
browser versions. Authors are encouraged to make more closely related
and descriptive checks, such as:

// See https://developer.mozilla.org/en-US/docs/DOM/HTMLCanvasElement
var isCanvasToBlobSupported = typeof x.toBlob == "function";
Twitter: @xkit
Received on Wednesday, 16 January 2013 21:14:34 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:08 UTC