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

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];

-- 
Glenn Maynard

Received on Wednesday, 3 August 2011 15:47:18 UTC