Re: Simplifying element creation

On Thu, 06 Oct 2011 00:51:09 +0200, Jonas Sicking <jonas@sicking.cc> wrote:
> It sounds to me like we're creating a JSON format for the DOM and
> making element.append accept the JSON format. This doesn't sound great
> to me. It basically sounds like too high level to fit enough use
> cases.

How it too high-level? Inserting elements and text nodes is the 80/20 of  
the DOM. And providing a viable simple alternative to innerHTML seems like  
a major win.


> It seems better to have an API for creating a single element (with
> attributes and event handlers), and then let people combine calls to
> that to do their own JSON->DOM conversion.
>
> Possibly it would make sense for the function to take an additional
> string-argument is used to create a text node which is inserted as a
> child. But I don't think we should add complexity in the form of
> sometimes interpreting that string as a node-name and sometimes as a
> textnode value.

I'm not sure what complexity you see. The first argument of the array sets  
the local name, later arguments set its children (which can in turn be  
other arrays). To allow multiple elements to be inserted we will use  
varargs.


-- 
Anne van Kesteren
http://annevankesteren.nl/

Received on Thursday, 6 October 2011 08:47:00 UTC