8

Is there any way to call super.super.methodName in TypeScript. I want to avoid calling super.methodName, but I want to call the 2nd ancestor's methodName method.

Thanks.

István
  • 5,057
  • 10
  • 38
  • 67

1 Answers1

12

Not supported by TypeScript. You can however exploit the fact that member functions are on prototype and you can call anything with this so SomeBaseClass.prototype.methodName.call(this,/*other args*/)

Example:

class Foo{
    a(){alert('foo')}
}

class Bar extends Foo{
    a(){alert('bar')}
}

class Bas extends Bar{
    a(){Foo.prototype.a.call(this);}
}

var bas = new Bas(); 
bas.a(); // Invokes Foo.a indirectly
basarat
  • 261,912
  • 58
  • 460
  • 511