Re: node.insertBefore( child )

>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 UTC