Subj : classes, turtles, and prototyping To : netscape.public.mozilla.jseng From : colsebas@hotmail.com (Friederich Munch) Date : Mon Mar 10 2003 12:09 pm I've had an existing "embedding" that worked, but wanted to change the underlying structure. So that, instead of "Amph_Turtle.getColor()", it would be "Amph.Turtle.getColor()" used to init Turtle like this: JSBool DoClass(JSContext *cx, JSObject *globalObject) { JS_InitClass(cx, globalObject, NULL, ...Turtle class params...); // Then I get the Constructor object, and define some functions on it for ease } now init turtle like this: JSBool DoClass(JSContext *cx, JSObject *globalObject) { JSObject *baseObj = JS_InitClass(cx, globalObject, NULL, ...Amph class params...); JS_InitClass(cx, baseObj, NULL, ...Turtle class...); // Then I get the Constructor object, and define some functions on it for ease } baseObj's resolve/enumerate/property ops mimic the globalObject's, and the only difference in the classes is that the names no longer start with "Amph_", Previously: > var turtleOne = new Amph_Turtle; [ object Amph_Turtle] > var turtleTwo = Amph_Turtle.createTurtle(); [ object Amph_Turtle] both turtleOne and turtleTwo would return true with "instanceof Turtle", and the also had any methods that turtle was inited with (i.e. turtleOne.getColor() and turtleTwo.getColor() were both valid mathods, and returned proper values) Now > var turtleOne = new Amph.Turtle; [ object Turtle] > var turtleTwo = Amph.Turtle.createTurtle(); [ object Turtle] now they both return as though they be Turtles, but they both return false with "instanceof Turtle", and have none of the methods (i.e. turtleOne.getColor() and turtleTwo.getColor() fail because the JS_Engine says geColor is not a function) whats going on? I really want to have the structure of "Amph.Turtle" and "Amph.Frog", where now I'm using something like "Amph_Turtle", and "Amph_Frog". .