473,396 Members | 1,864 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,396 software developers and data experts.

determine object's pointer name

Expand|Select|Wrap|Line Numbers
  1. mywidget = new Widget()
  2. alert(mywidget) // object Object
  3. alert(mywidget.toString()) // object Object
  4. alert(mywidget+"") // object Object
  5. alert(String(mywidget)) // object Object
  6.  
I have always wondered if there was a way to get the string "mywidget".

A potential use could avoid things like this:

Expand|Select|Wrap|Line Numbers
  1. Widget.widgetcount = 0
  2. function Widget() {
  3.    this.name = "mywidget"+(Widget.widgetcount++);
  4.    document.getElementsByTagName('body').item(0).appendChild(makeDiv(this.name+'Div'));
  5. }
  6. function WidgetTwo(name) {
  7.     document.getElementsByTagName('body').item(0).appendChild(makeDiv(name+'Div'));
  8. }
  9. function makeDiv(newID) {
  10.     var newDiv=document.createElement("DIV");
  11.     newDiv.id = newID;
  12.     return newDiv;
  13. }
  14. homer = new Widget()
  15. marge = new Widget()
  16. bart = new WidgetTwo("bart")
  17. lisa = new WidgetTwo("lisa")
  18.  
then the css would look like this:

Expand|Select|Wrap|Line Numbers
  1. #mywidget0Div {
  2. }
  3. #mywidget1Div {
  4. }
  5. //and
  6. #bartDiv {
  7. }
  8. #lisaDiv {
  9. }
  10.  
The first style forces the naming convention on you, the second style has redundancy. What I have always hoped for is:

Expand|Select|Wrap|Line Numbers
  1. function WidgetThree() {
  2.    this.name = magicalFunctionThatReturnsPointerNameAsString()
  3.    document.getElementsByTagName('body').item(0).appendChild(makeDiv(this.name+'Div'));
  4. }
  5. maggie = new WidgetThree()
  6.  
  7.  
  8.  
  9. #maggieDiv {
  10. }
  11.  
Is there any way to do this?
Sep 19 '06 #1
1 1362
acoder
16,027 Expert Mod 8TB
I don't think so, though you could possibly use the window object and loop through its child objects. WidgetTwo seems like the best approach.
May 13 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
19
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
3
by: abhimanyu | last post by:
I have a method Marshal.IsComObject(...) that returns TRUE if an object is a COM object. I have an object of Excel.Worksheet that I released using Marshal.ReleaseComObject(...). I want to iterate...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.