István
István

Reputation: 5127

TypeScript super.super call

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.

Upvotes: 8

Views: 2882

Answers (1)

basarat
basarat

Reputation: 275799

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

Upvotes: 12

Related Questions