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?
Get your object’s constructor function and then inspect its name property.
Returns “myClass”.