473,698 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

determine object's pointer name

8 New Member
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 1371
acoder
16,027 Recognized Expert Moderator MVP
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
2882
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 that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
19
2086
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 that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
18
1245
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 that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
3
5606
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 over a collection of Excel.Worksheet and find out which is disposed. Currently the workaround for me (bad one) is try { string name = worksheet.Name;
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9028
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.