Re: Node append

On Thu, 15 Sep 2011 21:37:13 +0200, Erik Arvidsson <arv@chromium.org>  
wrote:
> This is something that the centithreads regarding Element.create
> reminded me of...
>
> It would be useful to add an append method to the Node interface. It
> would work as the rest args in Element.create where it would just
> append Nodes to the end of the childNodes and it would toString() and
> create Text nodes for everything else.
>
> var element = ...;
> element.append(otherNode, "some text", 42, {toString: function() {
> return 'x' }});
>
> On this topic, it would be useful if the current DOM methods
> (appendChild, insertBefore and replaceChild) could all be changed to
> support Strings too.

I have now overloaded Node.appendChild(), Node.insertBefore(),  
Node.replaceChild(), and Range.insertNode(), with DOMString. If a string  
is passed a Text node representing that string is created and everything  
else will function as normal.

Passing a non-string such as 42 will throw per Web IDL. This does not seem  
like a major problem.


I have deferred adding arrays for now. I need to talk to Cameron (who is  
away) what the best strategy would be for them.


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

Received on Friday, 30 September 2011 13:43:42 UTC