- From: Dominic Cooney <dominicc@chromium.org>
- Date: Tue, 4 Oct 2011 18:18:18 +0900
- To: Anne van Kesteren <annevk@opera.com>
- Cc: "www-dom@w3.org" <www-dom@w3.org>
On Tue, Oct 4, 2011 at 5:30 PM, Anne van Kesteren <annevk@opera.com> wrote: > So far we discussed having Element.create() and having new methods on Node > that would be more practical than what we have today. Maybe we should > combine these in some way? Charles proposed some kind of JSON serialization, > but I do not think it makes sense to tie it to JSON. > > It could be something like this: > > ELEMENT = [NAME, optional ATTRS, optional EVENT_HANDLERS, TEXT | ELEMENT > ...] > > E.g. <div>Hello <a href="/">World</a></div> is represented as: > > ["div", "Hello ", ["a", {href:"/"}, "World"]] This is good in that it doesn't require any new bound identifiers. I think readability suffers a bit because element names and text are both strings. If you want to pass a list of children as a parameter, there is also no good serialization for it. Using a list is weak because it is the same type as an element. What about using constructor functions for elements? [HTMLDivElement, 'Hello ', [HTMLAElement, {href: '/'}, 'World']]. > Then the new methods we introduce could accept the above syntax to make it > easier to append new elements to the DOM. > > ele.append(['div']) > > would append a <div> element. If you want to append several elements, you > would use > > ele.append("Hello ", ["i", "World"]) > > I.e. append() takes "infinite" arguments. > > > -- > Anne van Kesteren > http://annevankesteren.nl/ > >
Received on Tuesday, 4 October 2011 09:18:45 UTC