Subj : Re: finilize & construct: call disbalance To : netscape.public.mozilla.jseng From : anton muhin Date : Thu Jul 15 2004 03:01 pm Brendan Eich wrote: > The prototype is just the first, and "representative" object of the > class. All instances after it delegate to it. Why should it not be of > the same class as those instances? In fact if it is to have shared > properties such as methods defined once as its properties, then it may > need class-specific [[Get]] and [[Put]] behavior (SpiderMonkey's > JSClass.getProperty, JSClass.setProperty). > > It makes less sense to insist that the prototype be a plain Object. > >> Another reason, but technical one, is that I don't want to check if my >> object has private data. It's not laziness, but rather I try to make >> things as clean as possible. > > Then give the prototype private data too, by calling your constructor on > it after the return from JS_InitClass. Ok, maybe I should be more specific. I want to extend js with one class --- RGB color plus a couple of utilities (it's actually VRML SFColor class). Each instance has color values and, therefore, all the methods can operate on it. However, I don't see any reasonable values for colors that prototype object should have. Of course, I can default to something like .0, .0, .0. By now I ended with checking of private data presence, but I still don't think that it's an ideal solution. Any comments and suggestions are highly appreciated. Maybe I'm just too OOPish for prototype-based languages. Anyway, thank you very much for your time and experience you shared! with the best regards, anton. .