W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2011

Re: Element.create(): a proposal for more convenient element creation

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Wed, 3 Aug 2011 08:50:43 -0700
Message-ID: <CAAWBYDD5AHU5tujRDV5CN-Vvri-o4O2aweMdGA_oJCr+YhUihA@mail.gmail.com>
To: Glenn Maynard <glenn@zewt.org>
Cc: Anne van Kesteren <annevk@opera.com>, Aryeh Gregor <ayg@aryeh.name>, Maciej Stachowiak <mjs@apple.com>, WebApps WG <public-webapps@w3.org>
On Wed, Aug 3, 2011 at 8:46 AM, Glenn Maynard <glenn@zewt.org> wrote:
> On Wed, Aug 3, 2011 at 3:34 AM, Anne van Kesteren <annevk@opera.com> wrote:
>> On Tue, 02 Aug 2011 20:31:04 +0200, Tab Atkins Jr. <jackalmage@gmail.com>
>> wrote:
>>> Hmm, is everything exposed as on* attributes now?  If so, then yeah,
>>> just do that; no need to mess around with a magic property in the
>>> attributes bag.
>>
>> This would still be magical as it is setting an IDL attribute rather than
>> a content attribute.
>
> What's the difference?  I'd expect this:
>
> a = Element.create("a", {href: "http://link", onclick: function(e) { },
> custom: "value" }, "link");
>
> to be essentially equivalent to
>
> a = document.createElement("a");
> a.appendChild(document.createTextNode("link"));
> attrs = {href: "http://link", onclick: function(e) { }, custom: "value" };
> for(key in attrs) a[key] = attrs[key];

Yes, because there you're setting the IDL attributes.  Anne's assuming
that the intended virtual implementation instead has this as the final
line:

for(key in attrs) a.setAttribute(key,attrs[key]);

This would obviously produce a different result here, as the function
would be stringified into something useless.

For most attributes, there's no difference between the two approaches,
but a handful have significant differences.

~TJ
Received on Wednesday, 3 August 2011 15:51:38 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:46 GMT