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

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

From: Glenn Maynard <glenn@zewt.org>
Date: Wed, 3 Aug 2011 12:26:02 -0400
Message-ID: <CABirCh8ygdo-9hs8DNajCJMs8GiHZDuSYzD8gx61ZWmFuimD6g@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
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 11:50 AM, Tab Atkins Jr. <jackalmage@gmail.com>wrote:

> 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.
>

I think that means it's the wrong thing to do.  Within JavaScript code, you
should be able to represent JS functions as JS functions, not as strings
containing JS functions.

The reasons are obvious, I think, but to spell out one use case:

function createWidget(target)
{
    return Element.create("a", {
        onclick: function(e) {
            e.preventDefault();
            target.activated();
        }
    }, "widget");
}

which is much harder to do if the function is a string.

On Wed, Aug 3, 2011 at 11:51 AM, Anne van Kesteren <annevk@opera.com> wrote:
> Would you expect to write contenteditable as contenteditable or as
contentEditable? Also, would you expect custom to end up as a content
attribute on that <link> element? Because it will not with this code.

I'd expect contentEditable, not contenteditable.  I don't normally access
DOM object properties from JavaScript using their content attribute names.
I wouldn't expect a custom content attribute (there are cases where you want
to do that, but they're rare in my experience).

-- 
Glenn Maynard
Received on Wednesday, 3 August 2011 16:26:32 GMT

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