Subj : Re: Properties and Objects To : netscape.public.mozilla.jseng From : "Sterling Bates" Date : Wed Dec 03 2003 10:46 am "Joseph Smith" wrote in message news:42ffeec1.0312030413.2824b09e@posting.google.com... > Parent has an array of JSChilderen, when its created it creates a > bunch of new JSChilderen, and i am trying to use getProperty() to > simply tell the parent object to call the child objects output > function (ie from a script, var p = new Parent(); p.child.output;) Seems to me you just need () at the end of p.child.output. All functions have to be called with at least empty parentheses. > I have included the classes to show you what i am trying to do, if you > can explain how to pass in this fashion would be great help :) > Also if you can exain how this happens can you also show me how to go > from the static m_Childeren[0] that i am using for testing purposes, > into an index generated from the calling function (ie var p = new > Parent; p.child[40000].output) for example??? (Disclaimer before I continue: I'm not a C programmer. Brendan could come back and declare all of this to be wrong or the hard way to do things.) The short way to accomplish this, as far as I know, is to make "child" an array object: p = JS_NewArrayObject(cx, 0, NULL); JS_DefineProperty(cx, newProtoObj, "child", OBJECT_TO_JSVAL(p), NULL, NULL, JSPROP_ENUMERATE); Then allow script to create your children via p.child.push(new Child()); Then script can call p.child[40].output(); Next, create a non-classed function called CallOutputDebugString (dumb name, yes): JSBool CallOutputDebugString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSChild c = (JSChild *)JS_GetPrivate(cx, obj); c.OutputDebugString(cx, &rval); } This function (CallOutputDebugString) replaces JSChild::OutputDebugString in JSChild::Child_methods[]. Finally, you have to modify c.OutputDebugString to something like this: JSBool JSChild::OutputDebugString(JSContext *cx, jsval *rval) { const char *output = "Test output"; JSString *s = JS_NewStringCopyN(cx, output, 11); rval = STRING_TO_JSVAL(s); } I hope that most of that is correct. Someone'll correct what's wrong I'm sure. Good luck, Sterling .