I am trying to retrieve the class name from within a static method. It works from an ordinary method but not from within a static method
class MyNode{
constructor(){
var classname=this.constructor.toString().split ('(' || /s+/)[0].split (' ' || /s+/)[1];
console.log(classname);
}
static a_static_method(){
var classname=this.constructor.toString().split ('(' || /s+/)[0].split (' ' || /s+/)[1];
console.log(classname);
}
}
var obj=new MyNode(); // THIS WORKS, prints "MyNode"
MyNode.a_static_method(); // THIS DOESN'T, prints "Function"
I forgot to tell: it should work for the derived classes of MyNode.
this.constructor.nameinstead of that long regexp