View Full Version : How to get Object Name?
Hello List
again simple question (i think)
how can i get the object name, say if i have
function blah()
{
;
}
var foo=new blah()
var foo2=foo;
//here i like to alert the name of the Object blah() and get its name ( that is "blah")
alert( foo2...?????) ;
thanks!
its not exactly right but
foo2.constructor==Blah give gives me true
and foo2.constructor gives me all the function , but i need only the name...
joh6nn
06-27-2002, 08:26 PM
i'm not sure if that's possible.
adios
06-27-2002, 08:31 PM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="JavaScript">
Object.prototype.get_class = function() {
var sCon = this.constructor.toString();
if (sCon)
return sCon.slice(sCon.indexOf(' ') + 1, sCon.indexOf('('));
return null;
}
function blah() {;}
var foo = new blah();
var foo2 = foo;
alert(foo.get_class());
alert(foo2.get_class());
</script>
</head>
<body>
</body>
</html>
why just not add method to the Object object ...Great!
but are you sure its the only why ? with adding method?
ok.. so we know how to get the Object name But what if i have this:
function blah()
{
;
}
var foo=new blah()
and i like to get the name of the var that hold the Object (in this case 'foo')
its giving me [Object Object] every time i try to print foo
even if i make foo.toString() it gives me the constructor function (blah())
??
thanks
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.