Subj : Re: about defining object... To : netscape.public.mozilla.jseng From : celleris@naver.com (Youngsun Jeong) Date : Tue Sep 30 2003 09:37 pm Brendan Eich wrote in message news:<3F7A0217.5070205@meer.net>... > Youngsun Jeong wrote: > > >Next, I add JSFunction "my_plusAge()" to my_class. > > > > > > How do you do that, exactly? Please see below: file name : myobject.h #ifndef myobject_h___ #define myobject_h___ #include "jstypes.h" JS_BEGIN_EXTERN_C extern JSClass my_class; extern JSObject* InitMyobjectClass(JSContext *cx, JSObject *obj); extern JSFunctionSpec my_method; JS_END_EXTERN_C #endif /* dom_h___ */ file name : myobject.c #include "jsapi.h" #include "jsobj.h" #include "jsfun.h" #include "jsutil.h" JSClass my_class = { "myobject", 0, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, JSCLASS_NO_OPTIONAL_MEMBERS }; static JSFunctionSpec my_method[] = { {"my_plusAge", my_plusAge , 0,0,0}, {0, 0, 0, 0, 0} }; static JSBool my_plusAge(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,jsval *rval) { ... } JSObject* InitMyobjectClass(JSContext *cx, JSObject *obj) { JSObject *proto; proto = JS_InitClass(cx, obj, NULL, &my_class, NULL, 1, NULL, my_method, NULL,NULL); if(!proto) return NULL; return proto; } "my_class" has method "my_plusAge()", doesn't have any properties. And I add "InitMyobjectClass" to jsapi.c. See below: file name : jsapi.c ... #include "myobject.h" //added ... JS_PUBLIC_API(JSBool) JS_InitStandardClasses(JSContext *cx, JSObject *obj) { ... return js_InitArrayClass(cx, obj) && js_InitBooleanClass(cx, obj) && js_InitMathClass(cx, obj) && js_InitNumberClass(cx, obj) && js_InitStringClass(cx, obj) && InitMyobjectClass(cx, obj) && //added ... } What is wrong? And I want to know how do make the relation between "age" and "plusAge()". Thank you for any assistance. .