Subj : Re: [HELP] Not understanding GetProperty/DefineObject... To : t o b e From : Brendan Eich Date : Wed Oct 08 2003 10:37 am t o b e wrote: > If I succesfully call DefineObject on the global to instantiate a custom > class object (haven't called InitClass for that, BTW) why does my own > GetProperty fn then get called to retrieve it ? > > Since DefineObject calls DefineProperty on the parent, making my custom > class object a property of the parent, I would have expected the JS engine > to be able to find the new object from there. Your class getProperty and setProperty hooks will be called for all ids that do not have per-property getters and setters. If you want per-property getters and setters, define them with JS_DefineProperty. JS_DefineObject is just a shorthand for JS_NewObject;JS_DefineProperty (with defaulting-to-class getter and setter). > And where exactly am I > supposed to pull a reference to the newly created object from unless I cache > a * to JSObject somewhere in my own code... this seems kind of redundant. You don't need to do that. Just leave the ids you don't understand alone, do nothing for them. But if that still runs too much code in your class getProperty hook, e.g., you can avoid that hook being called for that property by defining only-for-that-id getter and setter, with JS_DefineProperty. > > Obviously I'm missing some fundamental understanding here.. I've trawled the > code but all I'm really getting are the what's and not the why's..does > anyone have a good overview of how all this fits together for me ? Have you read the docs at http://www.mozilla.org/js/spidermonkey/ ? There's nothing deeply mysterious here, though. You need to define getters and setters, or let the system default to the class getProperty and setProperty. You've done the latter, so either leave those ids alone, or do the former. /be .