Open Faleij opened 8 years ago
Ah yes, that's a much better solution than what is currently in there. I'll have to include that in the next update. Thanks for pointing that out!
Note the slightly different syntax for either retrieving base or derived type using the above method, e.g.
class A { }
const B = class B extends A {
get type () {
return {
self: Object.getPrototypeOf (this.constructor).name, // B
base: Object.getPrototypeOf (this).constructor.name // A
}
}
}
If you need to get the subclass of an instance in a parent method - just use
Object.getPrototypeOf(this).constructor