From:  subin_john@yahoo.com
Date:  11 Jan 2007 18:00:02 Hong Kong Time
Newsgroup:  news.mozilla.org/netscape.public.mozilla.jseng
Subject:  

Array of objects

NNTP-Posting-Host:  61.95.164.171

Hi,
We are trying to implement the interface between DOM and Javascript.
Say for eg. implementing the array of anchors object, within document,
so as to parse statement like document.anchors[1].href

This is the order we are calling Javascript API's:
1. Create new array object using JS_NewArrayObject that represents
anchors
2. Create new object using JS_NewObject which represents each object
inside anchors
3. Define the properties and functions using JS_DefineProperties and
JS_DefineFunctions.
4. Define this as one of the elements of the array using
JS_DefineElement.

5. Repeat 2,3 and 4 based on the number of array elements.

We've tested this approach and it works.


Now our queries:
1. How does the interpreter know which particular array element is
being accessed. Like in case of document.anchors[1].href,

how can we get the 1.
2. Is there anyway we can avoid step 5. That is instead of creating all
the elements of the array, a way in which we can specify that this is
the prototype of the array elements and avoid adding every single
element. 
3. Is this approach correct?
Thanks