Subj : Re: accessing methods of base class To : netscape.public.mozilla.jseng From : Brendan Eich Date : Sun Jul 20 2003 08:24 pm Michael Caines wrote: > I was mistaken, the output of the window.status statements led me to believe > this was the case. The Rectangle.prototype = new Shape statement does run the > Shape constructor though, does it not? I found this strange since at this point > one is still 'defining classes'. There is no such thing as a class in JS, and no phase of compilation or execution as 'defining classes'. Everything is a statement; declarations are preprocessed according to certain rules, but assignment statements run in order and according to the usual control flow rules. > Also, why does a call to the inherited getType method of a sub class (in this > case Rectangle or ThreeDRectangle) return 'Shape' (ie. the value from the base > class), even though the type var has been redefined? Is it possible to override > instance/private var's in the sub classes? As it is now it seems all three > 'versions' of the var exist separately. Your code says: function Shape(Number_x, Number_y) { var type = 'Shape'; var x = 0; var y = 0; . . . } Those variables are simply function locals, they are not instance or member variables of the objects created via 'new Shape(...)' expressions. If you want to set properties of the newly created object, assign 'this.type = "Shape"; this.x = ...'. This is all well-covered by David Flanagan's O'Reilly book, "JavaScript: The Definitive Guide." /be .