To get derived class name from Base class method
jquery, typescript
Solution
You need to use the name property of constructor, like so:
class Base {
public Add(value: any) {
alert(this.constructor["name"]); // alerts 'Derived' in this example
}
}
class Derived extends Base {
public Add(value: any) {
super.Add(value); // use super to call methods on the base class
}
}
(new Derived).Add('someValue');
Problem
I'm trying to get the name of derived type from base class method.I have classes as below: ``` export class Base{ public Add(value: any) { } } class Derived extends Base{ public Add(value: any) { Base.prototype.Add.call(this, value); } } ``` I tried using $.type(this) inside Add() of Base class which gives type as object.But while debugging code type of this is shown as "Object (Derived)". Is there any way to get this??