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

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 UTC