Getting the name of an object - is it possible?

T

Tom Szabo

Hi All,

Just wondering if it is possible to get the name and class name of an
object?

oC = new control("name", "something");
..

oAnRef = oC;.
..
now both oC and oAnRef pointing to the same object of class "control"

is it possible to get the name of the class? in this case it is a string:
"control"

is it possible to get the name ( or string representation ) of the var:

function MyName(){
????????
}

cName = oC.MyName();

so MyName would hold string "oC"

TIA,

Tom
 
M

Michael Winter

Just wondering if it is possible to get the name and class name of an
object?

No.

You can get a reference to the constructor function of an object with

objRef.constructor

but that won't give you the name of the function.

You certainly can't get the identifier name an object is assigned to. As
you pointed out yourself, an object can be referred to by more than one
identifier.

What are you attempting to accomplish? You might be looking in the wrong
direction.

[snip]

Mike
 
J

Julian Turner

is it possible to get the name of the class? in this case it is a string:
"control"

I think you use the "constructor" property.

I.e.

var myClass=oC.constructor;
is it possible to get the name ( or string representation ) of the var:

function MyName(){
????????
}

cName = oC.MyName();

so MyName would hold string "oC"

I don't think that objects keep track of what variables reference
them. An object could be referenced by one or more variables, so it
would be quite an overhead for that object to have to track all of
those variables.

This can lead to memory leaks if you have circular references:
o1-->o2-->o1.
 
T

Tom Szabo

Thanks :-(((

Julian Turner said:
I think you use the "constructor" property.

I.e.

var myClass=oC.constructor;


I don't think that objects keep track of what variables reference
them. An object could be referenced by one or more variables, so it
would be quite an overhead for that object to have to track all of
those variables.

This can lead to memory leaks if you have circular references:
o1-->o2-->o1.
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top