Subj : Re: Confused about enumerating To : Brian Genisio From : Brendan Eich Date : Tue Feb 17 2004 04:45 pm Brian Genisio wrote: > Hi all, > > I have an object, which is similar to an array, and I want it to be > enumerated in a specific way. For instance, I would want the following: > > for( name in myObject) > ... do something with name > > But, the properties are based off the data in the object, so I have > not registerd them as properties, with JS_SetProperty. > > How do I handle this enumeration? > > I have set my enumeration function for the object in the JSClass > struct, and I get an object in that callback, but I am not sure what I > am supposed to do. > > The only thing I can think of, is to add the properties to the object, > when the enumeration method is called. Is this correct? Yes. See JSCLASS_NEW_ENUMERATE and read jspubtd.h for a different approach that does not require you to set properties at the start of the enumeration. However, it's always good to make what for..in discloses match what can be accessed on a "get by get" basis, if you know the ids. IOW, all enumerable properties should appear to be properties, even if they're reflected from private data using some kind of shared (JSPROP_SHARED) prototype getter, e.g. /be .