Subj : spidermonkey api To : netscape.public.mozilla.jseng From : Jens Thiele Date : Thu Nov 04 2004 04:26 pm I am currently mapping c++ class-based inheritance to prototype based inheritance. In JavaScript: function Base() { }; Base.prototype.baseMethod = ... function Sub() { // Base.call(this); }; Sub.prototype.__proto__ = Base.prototype; Sub.prototype.specialized = ... see also: http://egachine.berlios.de/inheritance/ now in my native code for the c++ example i use the following _HACK_ to be able to create a constructor with a different name for the same internal [[class]]: JSBool BaseWrapper_init(JSContext *cx, JSObject *global) { if (!(BaseWrapper_proto = JS_InitClass(cx, global, NULL, &BaseWrapper_class, BaseWrapper_cons, 0, NULL, BaseWrapper_methods, NULL, NULL))) return JS_FALSE; return JS_TRUE; } JSBool SubWrapper_init(JSContext *cx, JSObject *global) { JSObject* subproto; // HACK const char *tmp=BaseWrapper_class.name; BaseWrapper_class.name="Sub"; subproto=JS_InitClass(cx,global, BaseWrapper_proto, &BaseWrapper_class, SubWrapper_cons, 0, NULL, SubWrapper_methods, NULL, NULL); BaseWrapper_class.name=tmp; if (!subproto) return JS_FALSE; return JS_TRUE; } to remove this hack i would have to nearly duplicate JS_InitClass and it seems i would have to use non-public api functions am i missing something? .