Given
class BaseClass{
count:number=0;
public someMethod=():void =>{
this.count++;
}
}
class ChildClass extends BaseClass{
public someMethod=():void=>{
super.someMethod();
//Do more work here.
}
}
I receive the error message:
Only public methods of the base class are accessible via the 'super' keyword.
@Basarat provides some information here but this seems like a real hack to the language. typescript arrow operator to define a function on prototype
How might this be done while preserving contextual use of 'this'?
Am I using arrow functions properly or should they really only be used as a method of declaring something like a callback?
thisis the class, and handling scope and context usingcall,applyor an arrow function where calling code changes that context.callin my own code), I found that the the context ofthiswas not consistent. I thought I could simply use the arrow function everywhere in my classes and thus callbacks to my class would just work and from an Angular perspective it did. As I discovered though, this prevents me from using #Typescript inheritance. I think in practice I will have to be selective in my usage of arrow functions.thisin a method is always the class instance. Callbacks are no excuse because they can and should be implemented with top-level functions. I have learned to live with using the fat arrow syntax, that is until I had the need to override methods. Bug filed, but I suspect it will be dismissed as "by design". typescript.codeplex.com/workitem/2491