Re: [DOM4]: Element.create

On Fri, Sep 16, 2011 at 4:31 AM, James Graham <jgraham@opera.com> wrote:

> I think we should just set (content) attributes; it makes for a very
> straightforward, easily understood, API.
>

It feels much more natural to set properties; IDL attributes are the
first-class citizen of DOM APIs, not content attributes.  Unfortunately, for
this particular API they become a bit ugly when the property you need to set
isn't directly on the object--most obviously style.cssText.

Content attributes do have a problem, mentioned previously: functions can
only be set as strings, preventing eg.:

Element.create("img", {
    "src": url,
    "onclick": (function(e) { this.clicked(e); return false; }).bind(obj);
};

I suppose you could wrap addEventListener to return the object, so you could
say:

Element.create("img", {
    "src": url
}.myAddEventListener("click", (function(e) { this.clicked(e); return false;
}).bind(obj), false);

which could then be chained; more powerful, if less pretty...

-- 
Glenn Maynard

Received on Friday, 16 September 2011 15:56:46 UTC