dean at edwards.name
Thu May 11 03:19:14 PDT 2006
On 11/05/06, Lachlan Hunt <lachlan.hunt at lachy.id.au> wrote:
> Dean Edwards wrote:
> > objects (especially with the introduction of Mozilla's Array Extras
> > ). 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
> Where in the DOM would that new node be added?
I guess mutator methods should throw an error. Because we are
subclassing Array, NodeLists don't have to behave /exactly/ the same
as Array objects. I guess the really useful methods are the iterator
methods introduced in recent versions of Firefox. Being able to use
these on NodeLists would be great.
More information about the whatwg