0

Is there possibility to override Object's method in JS using mechanism similar to super implementation like in Java?

var myObj = {
    func: function() {
        console.log("Hello from super method");
    }
}
myObj.func = function() {
    //call super implementation 
    //super.func()

    //do something in addition
    console.log("...some addition text");
}    
pumbosha
  • 221
  • 3
  • 11
  • Yes, but you'd need to inherit from `myObj` for that (`myObj = {__proto__: myObj, func() { super.func(); … }}`). Not decorate it. – Bergi Mar 23 '17 at 18:15
  • You're replacing the method when you write `myObj.func = ...`. You need to use prototypes. – Barmar Mar 23 '17 at 18:16

0 Answers0