TypeScript-Handbook icon indicating copy to clipboard operation
TypeScript-Handbook copied to clipboard

[Mixin] How can I mixin 2 classes with constructor

Open tups-ibl opened this issue 8 years ago • 1 comments

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?

tups-ibl avatar Jun 29 '17 08:06 tups-ibl

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.

mhegazy avatar Aug 14 '17 23:08 mhegazy