Subj : Callbacks from C/JS To : netscape.public.mozilla.jseng From : Andreas Podgurski Date : Mon Feb 16 2004 11:19 pm Hi! I'm wondering, what is the standard way to declare a callback mechanism with the JS-Interface? My plan would be to have a method in the calling object (There is the possibility to have several callbacks on one hook) which adds the callback, kind of function MyCallback() { } MyObject.AddCallback(MyCallback); and something similar in the C-Interface JSBool MyCallback(JSContext *lpContext,JSObject *lpObject,uintN argc,jsval *argv,jsval *rval) { return (JS_TRUE); } argv[0]=JS_NewFunction(lpContext,MyCallback,2,0,NULL,"MyCallback"); JS_CallFunctionName(lpContext,lpObject,"AddCallback",1,argv,&Res); But there are some problems or misunderstandings I run into. First, I don't understand, if I need to convert the JSFunction * into an object via JS_GetFunctionObject or do I pass the JSFunction * directly? How can I determine the datatype, if it is a function? I havn't found a JSVAL_IS_FUNCTION in the jsref.pdf. Maybe I'm on the wrong way at all, but I don't want to use a "mini-script" approach like in the web-browsers (onMouseover="scriptcall();"), because I want to limit the possibilities to functions for internal reasons. Thanks in advance, Andreas Podgurski .