is there a way to call a function from baseclass like overwrite.
Base Class
export class BaseClass {
constructor() {
//do something asynchronous
//than call initialized
}
}
Inheritance Class
export class InheritanceClass extends BaseClass {
initialized() {
// get called from base class
}
}
Do you mean like this:
class Base {
constructor(){
setTimeout(()=>{
this.initialized();
}, 1000);
}
initialized(){
console.log("Base initialized");
}
}
class Derived extends Base {
initialized(){
console.log("Derived initialized");
}
}
var test:Derived = new Derived(); // console logs "Derived initialized" - as expected.
Works well in the Playground (Ignore the odd red underline on setTimeout()
, which I think is a bug - it compiles and runs fine.)
You do need the method present on Base
, but you can override it in Derived
(with or, as in this case, without a call to super.initialized()
).
In order to do that you would need to have initialized as an abstract member of the abstract class. typescript currently does not support this however the feature has been asked for and there is a work item open for it:
http://typescript.codeplex.com/workitem/395
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With