I have a class like the following: this is part of the library, and I canโt change it at all (if I could, I would just overwrite it or subclass it in Java)
public class FirstClass { public FirstClass(SecondClass arg) { ... } public ThirdClass aMethod() { ... } ... }
I want to create a Javascript object using Rhino (so no comment that JavaScript is different from Java, I know that), but override the "aMethod" method.
So, in Java, I would do this ...
public class MySpecialFirstClass extends FirstClass { public FirstClass(SecondClass arg) { super(arg); } public ThirdClass aMethod() { ThirdClass toReturn = super.aMethod();
But I can not do it in Javascript. Things I've tried so far ...
function js_FirstClass(arg) { var temp = JavaAdaptor(FirstClass, { '<init>': FirstClass, aMethod: function() { var toReturn = super.aMethod();
I also tried ...
var myClass = new FirstClass(secondClass); myClass.aMethodOld = myClass.aMethod; myClass.aMethod = function() { var toReturn = aMethodOld();
Other offers?
source share