Get name of object or class

javascript

Solution

Get your object's constructor function and then inspect its name property.

myObj.constructor.name

Returns "myClass".

Problem

Is there any solution to get the function name of an object? ``` function alertClassOrObject (o) { window.alert(o.objectName); //"myObj" OR "myClass" as a String } function myClass () { this.foo = function () { alertClassOrObject(this); } } var myObj = new myClass(); myObj.foo(); ``` `for (var k in this) {...}` - there is no information about the `className` or `ObjectName`. Is it possible to get one of them?

Original source

Related problems