W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2011

Re: [DOM4]: Element.create

From: Glenn Maynard <glenn@zewt.org>
Date: Fri, 16 Sep 2011 11:56:18 -0400
Message-ID: <CABirCh-neggBS7UJou3E2dV56hXL1yMFROYE9ZBUYicrUNAphg@mail.gmail.com>
To: James Graham <jgraham@opera.com>
Cc: www-dom@w3.org
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

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

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:18 UTC