[Javascript] Listing Images on current page

liorean liorean at gmail.com
Thu Sep 6 10:59:30 CDT 2007


> David Dorward wrote:
> > If you had 'img' then you would have a collection of the image
> > elements, not an array.

On 06/09/07, Hassan Schroeder <hassan at webtuitive.com> wrote:
> ? Technically you'd have a NodeList, about which the W3C says:
>
> Interface NodeList
>
>      The NodeList interface provides the abstraction of an ordered
>      collection of nodes, without defining or constraining how this
>      collection is implemented.
>
>      The items in the NodeList are accessible via an integral index,
>      starting from 0.
>
> Which in a JS context sounds pretty array-ish-like to me. I mean,
> a rose by any other name... :-)
>
> But can you explain why (and how) you're distinguishing the two?

- Well, first of all, a NodeList doesn't inherit from Array.
- Second, it is programmatically immutable. (Well, in some implementations...)
- Third, it doesn't enumerate it's integer properties elements like arrays do.
- Fourth, it's a lazy list, with performance accordingly.
- Fifth, it always reflects the state of the document, so changes to
the document will always be visible in it if they affects the elements
in the list or their relations.


Oh, and HTMLCollection, NodeList, NamedNodeMap etc. can all be
considered to be DOM collections of different kinds, I wouldn't say
David was wrong. For example, I believe there is one piece of code
implementing them all in Opera.
-- 
David "liorean" Andersson



More information about the Javascript mailing list