473,326 Members | 2,012 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,326 software developers and data experts.

How do I get the name of my variable or object?

Hello

On the surface this would seem quite simple, but I'm blowed if I can find a
way to do it.

Let's say I create a variable:

var my_object = new Object();

now, I want to find out the name of my object, eg. "my_object". How do I do
this? To make things clearer, say I want to alert out the name of my object,
I might try something like:

alert(my_object.name):

this doesn't work, however. Any help appreciated...Jeremy.
Jul 20 '05 #1
2 37352


Jeremy Wray wrote:
Hello

On the surface this would seem quite simple, but I'm blowed if I can find a
way to do it.

Let's say I create a variable:

var my_object = new Object();

now, I want to find out the name of my object, eg. "my_object". How do I do
this? To make things clearer, say I want to alert out the name of my object,
I might try something like:

alert(my_object.name):

this doesn't work, however. Any help appreciated...Jeremy.


An object doesn't have a name, inside of the methods of an object you
simply refer to
this.property
to access the object's properties. Other than that there is no name of
an object and there can't be, what would you suggest the name to be with
a code of
var obj0, obj1;
obj1 = obj = new Object()

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
> Let's say I create a variable:

var my_object = new Object();

now, I want to find out the name of my object, eg. "my_object". How do I do
this? To make things clearer, say I want to alert out the name of my object,
I might try something like:

alert(my_object.name):


You can create your own constructor and pass the name to it.

function MyObject(name) {
this.name = name;
window[name] = this;
}

new MyObject('my_object');

alert(my_object.name);

http://www.crockford.com/#javascript

Jul 20 '05 #3

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

Similar topics

7
by: Brian Genisio | last post by:
Hi all, Does anyone know of a way in IE to determine the prototype name of an object? For instance, in Mozilla, I can say: junk = document.getElementById("myID"); alert(junk.toString());
2
by: Ben | last post by:
is there a login name variable that I can use in my ASP.net, VB.net program? I am trying to have different users access different webform as they login. thanks for any help
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: Peter | last post by:
Hi everybody, I'm a new in C# and have a problem I need to create dynamically the name of object let's say "obj1", "obj2" etc. They're hashtables (Action Script objects) I'm doing like...
2
by: Doug | last post by:
I am trying to work with an object and create it like so: EXTRA.Sessions oSessions = new EXTRA.Sessions(); This doesn't work because I get this error: 'Cannot create an instance of the...
2
by: -BA- | last post by:
Hi! I wonder if it is possible to dynamically name a object (e.g. checkbox, combox etc.) during runtime. I know I can create a object during runtime like this: Me.MyLabel = New Label...
11
by: simon | last post by:
hello, I have a form that has 10 dropdown lists in one section each of the dropdowns contain the same data what i'm looking to do is that when a user selects a value from one dropdown, change...
8
by: gel | last post by:
Hi I would like to pass a variable in and use it as part of a name of an object, something like below, where I pass the variable software into the function and use it as part of the name of the...
2
by: VMI | last post by:
In my Windows Form, is it possible to get the control name through object sender in an event handler? For example, in private void dataGridView_zip_KeyPress(object sender, KeyPressEventArgs e), how...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.