Re: Simplifying element creation

On Oct 4, 2011, at 8:26 AM, João Eiras <joao.eiras@gmail.com> wrote:

>>>> E.g.<div>Hello<a href="/">World</a></div>  is represented as:
>>>> 
>>>>  ["div", "Hello ", ["a", {href:"/"}, "World"]]
> 
> I consider using html fragments instead of json-like representations
> for bulk element creation more optimal. It's non-ambiguous and doesn't
> require many intermediate temporary objects, which just add
> unnecessary overhead, because they would have to be created,
> traversed, sanatized (handling getters and setters, or properties with
> unexpected types), while the html parser does one pass (in an ideal
> situation) and creates everything in one go.
> 

It's the process of stringifying an existing JS object structure that's motivating this discussion.

It's much more natural to program and manipulate a JS object than a string.

These examples are using strings, but in the real world, we're using variables and method calls. It's more efficient for the coder and the implementation to go from JS object to DOM than to have a middle step of JS to XML DOMString to DOM.

Received on Tuesday, 4 October 2011 16:27:13 UTC