我的目的:子类可以使用父类抽象类的函数,而不需要向父类传递任何显式数据。并且装饰器可以获取子属性类的值。
代码示例:
abstract class Parent{
contructor(){}
calc(){
a = children property 1;
b = children property 2;
console.log("result: " + a*b);
}
}
class Children extends Parent{
@propertydecorator
a : number;
@propertydecorator
b : number;
contructor(no1:number, no2: number){
this.a = no1;
this.b = no2;
}
}
要使用此儿童课程:
const children = new Children(2, 4);
children.calc() //function extends from Parent
结果应该是:
result: 8
问:如何使用装饰器完成上述任务?或者还有什么可以帮助我完成我的目的吗? 预先感谢!