473,414 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Getting the name of an object - is it possible?

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


Jul 23 '05 #1
3 1032
On Fri, 26 Nov 2004 16:05:45 +1000, Tom Szabo <to*@intersoft.net.au> wrote:
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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
> 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.
Jul 23 '05 #3
Thanks :-(((

"Julian Turner" <ju****@baconbutty.com> wrote in message
news:c4**************************@posting.google.c om...
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.

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
8
by: bryan | last post by:
Is there any way I can get the application path (the one returned by Request.ApplicationPath) in the Application_Start method in Global.asax? Request is not valid there. On a related note, is there...
4
by: Joe Schmoe | last post by:
All I want to to be able to take a two-column DataReader (One column with the Item ID number, the other with Item Description text) and load it into a Windows Forms ComboBox (Set to DropDownList...
3
by: Atul | last post by:
Hi, I am running .NET Framework 2.0 on windows XP SP2. I am stuck in a situation where I need to find out a list of all active sessions running in IIS for a web application. I know that .NET...
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
6
by: bill | last post by:
Thanks to those that taught me to use heredoc to embed html in php. I don't want to start the html in php vs php in html discussion again., heredoc works a treat for that which I am doing...
6
by: Adam Atlas | last post by:
Is it possible for an object, in its __init__ method, to find out if it is being assigned to a variable, and if so, what that variable's name is? I can think of some potentially ugly ways of...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.