Subj : Re: Preventing 'new' To : netscape.public.mozilla.jseng From : Jamie Nordmeyer Date : Fri Mar 25 2005 02:42 pm Hi again, Brenden. I'm doing this because I intend to have a Registry class with an OpenKey method that returns a reference to a RegistryKey class. However, now that I"m thinking about it, I suppose something like 'var x = new RegistryKey(HKEY_LOCAL_MACHINE, "\\Software", REG_CREATE | REG_OPEN);' could work. I'll have to give it some thought. Either way, thanks again. "Brendan Eich" wrote in message news:42449278.3010902@meer.net... > Jamie Nordmeyer wrote: > > How do you hide an object's constructor so that you can't 'new' that object? > > Essentially, I want to be able to create the object in my C++ code, but the > > Javascript user should NOT be able to. They should have to do the > > following: > > > > var objB = objA.CreateObjB(); > > > Why do you want to require that? > > If you don't want a constructor, don't define one. You can pass null as > the |constructor| parameter to JS_InitClass, and you'll get the class's > prototype object named by the class's name in the global object, instead > of a constructor function with a property named 'prototype' referencing > the class prototype. > > /be .