Subj : Re: [Q] Persuading DOMNodeList/DOMHTMLCollection to look like arrays...
To : netscape.public.mozilla.jseng
From : Brendan Eich
Date : Fri Jan 30 2004 12:26 pm
t o b e wrote:
>More browser related Javascript implementation fun..
>
>IE & Navigator allow both of the following ways to access a list
>(HTMLCollection in this case).
>
>document.forms[index]
>document.forms.Item(index)
>
>I have the Item() bit in place. Now if I only I could persuade a square
>bracket element access to end up at item(). Does anyone have any ideas about
>how to implement this ? My first thought was to specialise Array but after
>poking around I couldn't find any obvious way to do this.
>
Array is a red herring -- JS allows [] to be used to access any property
of any object.
> A quick play with
>enumeration doesn't seem to yield much of use either. Obviously I'm barking
>up the wrong tree here so does anyone have any ideas in this direction.
>
Whatever JSClass implements forms, if its getProperty method checks
JSVAL_IS_INT(id) and then uses non-negative int ids to access items in
the same way that Item() does, you're done.
/be
.