Timo Rütten Timo Rütten - 1 month ago 5x
Javascript Question

Get name of object or class in javascript

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 () {

var myObj = new myClass();

for (var k in this) {...} - there is no information about the className or ObjectName. Is it possible to get one of them ? In PHP its possible - but i did not find any solution in the internet to get it in javascript.


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


Returns "myClass".