![](/img/trans.png)
[英]How to add a class to a KendoUI Grid for angular2+ component base element?
[英]How to get the derived class name in the base class (Angular2+)?
当我有一个扩展基类的类时,如何获得派生类的名称(在基类中)?
我在基类中有一个被派生类调用的方法。 我想知道哪个实例正在调用该方法。 使用this.constructor.name可以得到当前的基类,而不是派生的基类。
角4/5
谢谢。
[更新]
您需要使用构造函数类的name属性。
class Base {
public process(value: any) {
alert(this.constructor["name"]); // alerts 'Derived' in this example
}
}
class Derived extends Base {
public process(value: any) {
super.process(value); // use super to call methods on the base class
}
}
(new Derived).process('someValue');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.