TypeScript-Handbook
TypeScript-Handbook copied to clipboard
[Mixin] How can I mixin 2 classes with constructor
For example:
class Point {
constructor(public x: number, public y: number) {}
where(){
return console.log(this.x,this.y);
}
}
class Person {
constructor(public name: string) {}
who(){
return console.log(this.name);
}
}
How can I mixin 2 classes like this?
How can I mixin 2 classes like this?
You can not mix in a two classes with constructors that have logic like the ones above. at run time only one constructor will be called.
You can have a class PointPerson that would explicitly call the constructors of both and mix in the static sides separately.