You are probably looking for:
function MyClass() {}; var myInstance = new MyClass(); console.log(myInstance.constructor.name === "MyClass");
For this to work, you must declare a function as above, and not use MyClass = function(){} . Then the name property of the function is used, using the prototype chain (when querying the constructor property).
If you need to access directly in the constructor, use the link to the constructor:
function MyClass() { console.log(this.constructor.name === "MyClass"); }; var myInstance = new MyClass();
This question relates to a similar topic, it may be useful for you too: Get name as String from Javascript function reference?
source share