Subj : Spidermonkey: How to call a 'static method' from C To : netscape.public.mozilla.jseng From : Peter Paulus Date : Tue May 25 2004 02:18 pm Hello all, In our project we want to be able to call a 'static method' or class-like method from C or C++. With the compilable and executable javascript below I've tried to accomplish this: XYZHandler = function(name) { this.name = name || "untitled"; } XYZHandler.prototype = new Object(); XYZHandler.superclass = Object.prototype; XYZHandler.prototype.constructor = XYZHandler; XYZHandler.onOpen = function() { .... } XYZHandler.onClose = function() { .... } onOpen = function() { .... } onClose = function() { } XYZHandler.main = function(argc, argv) { var handler = new XYZHandler("Handler1"); XYZHandler.onOpen(); XYZHandler.onClose(); onOpen(); onClose(); } XYZHandler.main(); I now want to call functions XYZHandler.onOpen() or XYZHandler.onClose() from my C++ environment: void CallFunction() { jsval result = 0L; JSScript* script = JS_CompileFile(context, globalObj, sourceFile); JSBool ok = JS_ExecuteScript(context, globalObj, script, &result); if (not ok) { ... } ok = JS_CallFunctionName(context, globalObj, "XYZHandler.onOpen", 0, NULL, &result); if (not ok) { ... } .... } My 'ErrorReporter' now says: 'TypeError: undefined is not a function'. If I however use the function name "onOpen" [JS_CallFunctionName(context, globalObj, "onOpen", 0, NULL, &result)] , the JS_CallFunctionName succeeds. How can one call these class-like or static methods? With kind regards, Peter Paulus .