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

On 8/2/11, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> On Tue, Aug 2, 2011 at 9:48 AM, Aryeh Gregor <ayg@aryeh.name> wrote:
>> On Mon, Aug 1, 2011 at 9:33 PM, Maciej Stachowiak <mjs@apple.com> wrote:
>>> In an IRC discussion with Ian Hickson and Tab Atkins, we can up with the
>>> following idea for convenient element creation:
>>> Element.create(tagName, attributeMap, children…)
>>>    Creates an element with the specified tag, attributes, and children.
>>
>> How does this compare to popular JS helper libraries like jQuery?  It
Looking at it from a utilitarian perspective, I don't see why it matters.

>> would be useful to know what convenience APIs authors are using now
>> before introducing our own.
>
> jQuery's element creation is basically driven by innerHTML.  That is,
> to create an element, you just make a call like "$('<p class=foo>')".
> I doubt that's a pattern we actually want to copy, as it's kinda
> dirty, and inconvenient in some cases.  (For example, to apply a bag
> of properties as attributes,

Lost me on that one. Bag of properties? jQuery fumbled with confusing
attributes and properties for many years. No idea what they do now,
but probably similar.

you have to first create the element,
> then call attr() on it.  You can't pass the attrs as an initial arg
> without string-building.)
>
> Prototype's element creation is almost identical to what is proposed
> here, except it uses something that looks like a constructor.  You
> create an element with "new Element('p',{class:'foo'})".  You can't
> set children as part of the initial call; they have to be appended in
> later calls.
>
And that is the reason that it's no good to go messing with this.
Prototype defines Element as a Function, there is the interface object
that is an Object.


> MooTools is basically identical to Prototype, except that you can
> additionally set listeners on the element during creation by using a
> magical "events" property in the attribute bag, which takes an object
> of event names and functions.  This would be nice to look into adding.
>
Nope.
[...]
Big waste of time.
-- 
Garrett

Received on Tuesday, 2 August 2011 18:27:59 UTC