Subj : Re: How to distinguish objects of the same type in C? To : netscape.public.mozilla.jseng From : Weiyang Zhou Date : Thu Aug 11 2005 11:05 am When you say destructor, you mean the finalize function, right? "Peter Wilson" wrote in message news:ddett0$jv2@ripley.netscape.com... > Weiyang Zhou wrote: >> Hi, >> >> If I use JS_initClass to define a class Foo, the contructor will allocate >> some instance data in C for the object created. I also use >> JS_DefineFunction to define a function called fooOp(). Assuming the C >> implementation of this function is fooOp_native(). >> >> With the following JavaScript: >> >> f1 = new Foo(); >> f2 = new Foo(); >> >> fooOp(f1, f2); >> >> In fooOp_native(), I will need to retrieve the instance data from each >> object. How should I do that? >> >> I have read jsdate.c, seems it uses OBJ_SET_SLOT/OBJ_GET_SLOT, but it is >> not in jsapi.h. Or should I use JS_SetPrivate/JS_GetPrivate? >> >> Thank you >> Weiyang >> > I use JS_SetPrivate/JS_GetPrivate for a number of native classes - does > everything I need. I also hook into the destructor to make sure I release > private data when the JS equiv is garbage collected. > > Pete > -- > Peter Wilson. http://www.whitebeam.org, http://www.yellowhawk.co.uk .