Subj : Re: Equivalent of JS_InitClass for global object? To : "John J. Lee" From : Brendan Eich Date : Sun Aug 24 2003 02:37 pm John J. Lee wrote: >Your reply got my mental gears turning on a number of issues, thanks. > >One thing I don't understand: The JS_InitClass docs say: > >| JS_InitClass builds a class structure, its object constructor, its >| prototype, its properties, and its methods. A class is an internal JS >| structure that is not exposed outside the JS engine. You can use a >| class, its properties, methods, and prototypes to build other objects >| that are exposed outside the engine. > >which seems at first glancce to be in contradiction to your reply: > The docs lie, they were written by some Netscape techwriter no longer around, who sometimes made up facts (probably frustrated by lack of response from engineers who might know -- at the time, I had left the JS group I'd founded to co-found mozilla.org). Sorry about this, it's something that should be fixed. > >Brendan Eich writes: >[...] > > >>This will work -- you need not call JS_InitClass to use a JSClass >>struct. You need to call JS_InitClass only if you have a class >>constructor, and want it to be named by the class name, and to have a >>class prototype; or, if you pass null for the constructor, to have the >>class name denote the class prototype object (e.g., Math). >> >> >[...] > >because, if a class isn't exposed outside the API, why else would one >want to call JS_InitClass unless one is *required* to call it on *all* >JSClass structures? > That doesn't follow at all. You can use a statically initialized JSClass struct by passing its address to JS_NewObject as the second parameter. See js.c's 'glob = JS_NewObject(cx, &global_class, NULL, NULL);' without any prior or later JS_InitClass on that global_class struct. >I assume there's no reason to require "window" to *really* be the >global object? > There is if you want to run scripts from real-world web pages, especially those that know about multiple windows (frames in framesets, top-level windows). /beJohn .