How parent class get all children properties data using decorator in typescript?

152 Views Asked by At

My purpose: Children class can use function of Parent abstract class without pass any explicit data to the parent. And decorator can get the value of children properties class.

Code example:

abstract class Parent{
constructor(){}
calc(){
a = children property 1;
b = children property 2;
console.log("result: " + a*b);
}
}

class Children extends Parent{

@propertydecorator
a : number;
@propertydecorator
b : number;
constructor(no1:number, no2: number){
this.a = no1;
this.b = no2;
}
}

To use this Children class:

const children = new Children(2, 4);
children.calc() //function extends from Parent

and result should was:

result: 8

Ask: How can i do above task with decorator? Or any thing else help me complete my purpose? Thank in advance!

0

There are 0 best solutions below