Re: Node append

On 17/09/11 1:13 AM, Anne van Kesteren wrote:
> On Thu, 15 Sep 2011 21:37:13 +0200, Erik Arvidsson <arv@chromium.org> 
> wrote:
>> 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.
>
> This seems like a nice plan. Note that if we overload appendChild with 
> DOMString it would throw for anything non-Node non-DOMString. We could 
> make everything stringify by using a special IDL operator (e.g. as 
> XMLHttpRequest does for send()), but depending on what we want to do 
> in the future that might make extensions harder.
>
> Maybe instead of a new append() method we could simply make the 
> methods that already accept DocumentFragMent accept arrays too? The 
> arrays would be valid as long as they only contain nodes 
> DocumentFragment can contain or DOMString.
>
> Let me know what you think.
>
>

So, feature detection would involve:

try { document.createElement("div").appendChild(["hello"]); }
catch (e) { /* feature not available */ }

I'm fine with this but I thought it was generally looked down upon.

Sean

Received on Wednesday, 21 September 2011 02:28:33 UTC