Subj : Re: [Rhino] Inheritance To : netscape.public.mozilla.jseng From : igor@icesoft.no (Igor Bukanov) Date : Thu Jan 09 2003 02:59 am "Todd Trimmer" wrote in message news:... > 1) defineClass won't work on an abstract class > 2) If I have java.Derived extends java.Base: > A. I want js.Derived > B. I don't want js.Base to exist. Period. Not even for a prototype. > C. I want java.Derived to silently pull inherited methods from java.Base > into its js.Derived signature. > 3) defineClass using getMethods instead of getDefinedMethods achieves > exactly what I describe above. You can file a new bug at bugzilla.mozilla.org, where you should select Rhino as a component name and mark it as enhancement. > > How do I do: > > ScriptableObject.defineClass(scope, Base.class); > ScriptableObject.defineClass(scope, Derived.class); > Scriptable baseProto = ScriptableObject.getClassPrototype(scope, > base-js-class-name); > Scriptable derivedProto = ScriptableObject.getClassPrototype(scope, > derived-js-class-name); > derivedProto.setPrototype(baseProto); > > > But inside the javascript shell? This doesn't work: You can export a new method to the shell with necessary Java code or use __proto__ field to alter prototype chain of the already created JS object, like in: Derived.prototype.__proto__ = Base.protoype; which is an extension to EcmaScript. Note that when you assign Derived.prototype.prototype = Base.protoype; you does not change the prototype chain, you just define new property called "prototype" in Derived.prototype object. Regards, Igor .