[whatwg] Intergrating the DOM and JavaScript (JSDOM)
Lachlan Hunt
lachlan.hunt at lachy.id.au
Wed May 10 23:17:08 PDT 2006
Dean Edwards wrote:
> It would be great if NodeLists were subclasses of JavaScript Array
> objects (especially with the introduction of Mozilla's Array Extras
> [1]). This makes iteration over DOM queries more flexible.
It sounds like a nice idea, but there are some problems with it that I
can see. NodeLists are live, meaning that changes made to the
underlying DOM will be reflected in the list. Conversely, it means that
any changes made to the NodeList would logically need to be reflected in
the DOM.
e.g. If you get a node list of P elements like this
var pNodes = document.getElementsByTagName("p");
then later in the script you remove one of those P elements from the
DOM, it will also be removed from that NodeList.
This is a problem for your idea because it means that changes made to
the NodeList would also need to be made to the DOM, in order to keep
them in sync.
e.g. What would happen if you used the Array push() function on the
NodeList?
pNodes.push(newNode);
Where in the DOM would that new node be added?
--
Lachlan Hunt
http://lachy.id.au/
More information about the whatwg
mailing list