W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2006

[whatwg] Intergrating the DOM and JavaScript (JSDOM)

From: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Date: Thu, 11 May 2006 16:17:08 +1000
Message-ID: <4462D6E4.1010204@lachy.id.au>
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/
Received on Wednesday, 10 May 2006 23:17:08 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:27 UTC