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

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 UTC