W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2003

Re: node.insertBefore( child )

From: Joseph Kesselman <keshlam@us.ibm.com>
Date: Wed, 3 Dec 2003 14:39:36 -0500
To: www-dom@w3.org
Message-ID: <OFF33012EF.60743EB7-ON85256DF1.006B8E23-85256DF1.006BFEF9@us.ibm.com>





>As long as we're on the subject of .insertBefore()
>Why does this method, when no second argument is specified, append the
child?

The next-sibling of the last sibling is null. Hence, insert-before null is
taken as a request to insert at that point.

Did we have to support that behavior? No. But it's cheap and easy to
implement, it makes sense when you understand the rationalle, and it makes
some kinds of code a trifle easier to write.

Would you really have preferred that we throw a null pointer exception?

(It's far too late to change it, in any case.)


>Why not make this call as simple as:
>node.insertBefore( list[ i ] );

We have something like that. Rather than using a list to hold your nodes,
make them children of a DocumentFragment node, which has the magic property
that inserting/appending it actually inserts/appends its children.


______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
Received on Wednesday, 3 December 2003 14:47:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:57 GMT