Subj : Re: SpiderMonkey newbie question To : Andy Madigan From : Brendan Eich Date : Tue Sep 28 2004 11:23 pm Andy Madigan wrote: > I'm trying to figure out how to create JavaScript "classes", in the > apidoc for JS_InitClass > (http://www.mozilla.org/js/spidermonkey/apidoc/gen/api-JS_InitClass.html) That doc lies. The argument you must mean is named parent_proto, so it's the grand-proto of objects of this class, and you can pass NULL if Object.prototype is a fine grand-proto. JS_InitClass *always* makes a new prototype object, of the given class (not of Object class). This parent_proto argument, if non-null, becomes the proto of that prototype, if you get what I mean. > it seems to say that if you don't pass a prototype object, the class > won't init. It doesn't say that in the lying docs, and the code does not fail. > What I need is to be able to create a class where the > prototype is "new Object". Why would you want a plain Object rather than an unconstructed instance of the class you're initializing? > Is there a shortcut for this, or should I > try to evaluate the script "new Object" To make a new Object, just call JS_NewObject(cx, NULL, NULL, NULL). > and just get a prototype that > way. (Note: I know rhino, but SpiderMonkey makes very little sense to > me, since I'm used to C++, not C). Not sure how C++ helps here, but the docs are wrong, again -- sorry. I'll try to fix them, but I won't get to it soon. Anyone with CVS access can produce a patch (Sterling?) based on js/docs. /be .