W3C home > Mailing lists > Public > public-webapi@w3.org > March 2008

Re: [Bindings] 'new' behavior on interface objects

From: Cameron McCormack <cam@mcc.id.au>
Date: Wed, 19 Mar 2008 10:30:51 +1100
To: "Web APIs WG (public)" <public-webapi@w3.org>
Message-ID: <20080318233051.GC22818@arc.mcc.id.au>

Travis Leithead:
> Since this spec is presumably creating a language binding for
> JavaScript,

Yes, since ECMAScript ≈ JavaScript (for some value of JavaScript).

> (and assuming interface objects are Functions, as seen by
> Opera),

As mentioned in my previous e-mail, I think that assumption is false.
An object does not need to be a Function to be able to be used on the
right-hand side of the ‘new’ operator, though.  The object just needs to
implement [[Construct]].

> then why does:
> 
> var div = new HTMLDivElement();
> 
> produce a script error?

As Anne says, it’s because the object doesn’t have a constructor.

> Seems like a perfectly valid thing to do, essentially a shortcut to
> document.createElement('div')

In the new IDL, you could write

  [Constructor]
  interface HTMLDivElement : … {
    …
  };

if you wanted to indicate that the interface object must implement
[[Construct]].

Whether this is something that is desired on HTMLDivElement would be
something for the HTML WG to decide, since they will publish the IDL for
HTML 5.

-- 
Cameron McCormack, http://mcc.id.au/
	xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au
Received on Tuesday, 18 March 2008 23:31:39 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 18 March 2008 23:31:41 GMT