H
howa
A simple code like:
a = new User();
How can I print out the class name which a belong to?
Thanks.
a = new User();
How can I print out the class name which a belong to?
Thanks.
A simple code like:
a = new User();
How can I print out the class name which a belong to?
Thanks.
A simple code like:
a = new User();
How can I print out the class name which a belong to?
Thanks.
A simple code like:
a = new User();
How can I print out the class name which a belong to?
Thanks.
howa said:A simple code like:
a = new User();
How can I print out the class name which a belong to?
Straigth from the mozilla javascript manual:Lasse said:howa said:A simple code like:
a = new User();
How can I print out the class name which a belong to?
If you mean the name of the constructor function (Javascript has no
classes) then by default you can find the constructor method as:
var cons = a.constructor;
and you can extract the name from its string representation:
function functionName(func) {
var match = /function\s+(\w+)\b/.exec(func.toString());
if (match) {
return match[1];
} else {
return "[anonymous]";
}
}
Now, the big question is: What do you need this for?
Good luck
/L
Straigth from the mozilla javascript manual:
function a()
{
}
var b = new a();
alert(b.constructor.name); //Alerts "a"
Straigth from the mozilla javascript manual:
function a()
{
}
var b = new a();
alert(b.constructor.name); //Alerts "a"
Nikola said:[...]
Straigth from the mozilla javascript manual:
function a()
{
}
var b = new a();
alert(b.constructor.name); //Alerts "a"
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.