473,804 Members | 3,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing an object name

Hey all, for debugging purposes, I'd like to be able to access an
object's instance name from within the object class. For example, I'd
like to be able to do something like this:

------------------------------------------------------------
function FooClass() {
// definition of FooClass members
}

FooClass.protot ype.Debug = function() {
// Need help here to display correct information
alert("My name is ...?");
}

var monkeybutter = new FooClass();
monkeybutter.De bug(); // I'd like this to display "My name is
monkeybutter"
------------------------------------------------------------

Is this possible, and if so, how?
Nov 26 '07 #1
15 1866
On Nov 26, 5:57 pm, TonyV <kingskip...@gm ail.comwrote:
Hey all, for debugging purposes, I'd like to be able to access an
object's instance name from within the object class. For example, I'd
like to be able to do something like this:

------------------------------------------------------------
function FooClass() {
// definition of FooClass members

}

FooClass.protot ype.Debug = function() {
// Need help here to display correct information
alert("My name is ...?");

}

var monkeybutter = new FooClass();
monkeybutter.De bug(); // I'd like this to display "My name is
monkeybutter"
------------------------------------------------------------

Is this possible, and if so, how?
arguments.calle e construct might be of help.
http://www.devguru.com/Technologies/...arguments.html

Kailash Nadh | http://kailashnadh.name
Nov 26 '07 #2
VK
On Nov 26, 8:57 pm, TonyV <kingskip...@gm ail.comwrote:
Hey all, for debugging purposes, I'd like to be able to access an
object's instance name from within the object class. For example, I'd
like to be able to do something like this:

------------------------------------------------------------
function FooClass() {
// definition of FooClass members

}

FooClass.protot ype.Debug = function() {
// Need help here to display correct information
alert("My name is ...?");

}

var monkeybutter = new FooClass();
monkeybutter.De bug(); // I'd like this to display "My name is
monkeybutter"
var monkeybutter = new FooClass('monke ybutter');
function FooClass() {
this._name = arguments[0] || 'anonymous';
// definition of FooClass members
}

FooClass.protot ype.Debug = function() {
alert("My name is " + this._name);
}

Nov 26 '07 #3
On Mon, 26 Nov 2007 at 09:57:29, in comp.lang.javas cript, TonyV wrote:
>Hey all, for debugging purposes, I'd like to be able to access an
object's instance name from within the object class. For example, I'd
like to be able to do something like this:

------------------------------------------------------------
function FooClass() {
// definition of FooClass members
}

FooClass.proto type.Debug = function() {
// Need help here to display correct information
alert("My name is ...?");
}

var monkeybutter = new FooClass();
var a = monkeybutter;
var b = a;
var c = b;
>monkeybutter.D ebug(); // I'd like this to display "My name is
monkeybutter "
Now what do you want to display : "a", "b", "c", or "monkeybutt er"?
(Note : all those variables point to the same object).

What if you also did

d.e.f["fred"]().g.h = c;

Now what do you want to display?
>------------------------------------------------------------

Is this possible, and if so, how?
After a bit of thought you now realise that that was the wrong question.
As usual, you need to start with the right first question :

"What do I *really* want to do?"

From your first paragraph it looks as though you want each FooClass
object to hold its own object identifier. Then VK's solution is your
answer, though call it 'oid', not 'name', as 'name' is too likely to be
needed for real names. Now the oid can be something convenient or
significant, not restricted to the name of a global variable.

John
--
John Harris
Nov 27 '07 #4
On Nov 27, 3:50 pm, John G Harris <j...@nospam.de mon.co.ukwrote:
var a = monkeybutter;
var b = a;
var c = b;
monkeybutter.De bug(); // I'd like this to display "My name is
monkeybutter"

Now what do you want to display : "a", "b", "c", or "monkeybutt er"?
(Note : all those variables point to the same object).
Easy: "monkeybutt er."
After a bit of thought you now realise that that was the wrong question.
As usual, you need to start with the right first question :

"What do I *really* want to do?"
What I want to do is to have a debugging function in my class that
will tell me which instance of said class the particular debugging
information that follows applies to.
Nov 28 '07 #5
On Wed, 28 Nov 2007 at 12:22:45, in comp.lang.javas cript, TonyV wrote:
>On Nov 27, 3:50 pm, John G Harris <j...@nospam.de mon.co.ukwrote:
> var a = monkeybutter;
var b = a;
var c = b;
>monkeybutter.D ebug(); // I'd like this to display "My name is
monkeybutter "

Now what do you want to display : "a", "b", "c", or "monkeybutt er"?
(Note : all those variables point to the same object).

Easy: "monkeybutt er."
>After a bit of thought you now realise that that was the wrong question.
As usual, you need to start with the right first question :

"What do I *really* want to do?"

What I want to do is to have a debugging function in my class that
will tell me which instance of said class the particular debugging
information that follows applies to.
I'm afraid you're confusing us.

Your first sentence says you want to know which variable you used to
access an object.

Your second sentence says you want to know which object you accessed.

Which do you really want?

John
--
John Harris
Nov 29 '07 #6
John G Harris wrote:
On Wed, 28 Nov 2007 at 12:22:45, in comp.lang.javas cript, TonyV wrote:
>On Nov 27, 3:50 pm, John G Harris <j...@nospam.de mon.co.ukwrote:
>> var a = monkeybutter;
var b = a;
var c = b;

monkeybutter .Debug(); // I'd like this to display "My name is
monkeybutter "
Now what do you want to display : "a", "b", "c", or "monkeybutt er"?
(Note : all those variables point to the same object).
Easy: "monkeybutt er."
>>After a bit of thought you now realise that that was the wrong question.
As usual, you need to start with the right first question :

"What do I *really* want to do?"
What I want to do is to have a debugging function in my class that
will tell me which instance of said class the particular debugging
information that follows applies to.

I'm afraid you're confusing us.

Your first sentence says you want to know which variable you used to
access an object.

Your second sentence says you want to know which object you accessed.

Which do you really want?
It's easy enough to understand once you accept that he's asking for
something grossly impossible; he wants an object to magically remember
the name of the first variable it was ever assigned to.
--
John W. Kennedy
"Compact is becoming contract,
Man only earns and pays."
-- Charles Williams. "Bors to Elayne: On the King's Coins"
Nov 30 '07 #7
On Nov 29, 8:58 pm, "John W. Kennedy" <jwke...@attglo bal.netwrote:
It's easy enough to understand once you accept that he's asking for
something grossly impossible; he wants an object to magically remember
the name of the first variable it was ever assigned to.
--
John W. Kennedy
There's nothing magical about it, and in spite of the condescending
tone of that reply, it's not rocket science what I'm asking. I want
to know if there's a way for an object instance to have access to
information about itself, such as its name, if it has one.

If it can't, then just say so. If it can, then I'd appreciate knowing
how.
var a = monkeybutter;
var b = a;
var c = b;
monkeybutter.De bug(); // I'd like this to display "My name is
monkeybutter"

Now what do you want to display : "a", "b", "c", or "monkeybutt er"?
(Note : all those variables point to the same object).
In a case like this, as I said, I'd love to have "monkeybutt er," but
I'd even be pleased for something like an array containing the values
"monkeybutt er," "a," "b," and "c" if multiple references to the same
object instance exists.

I never said I wanted to know which object was being accessed. I've
been consistent in what I need the whole time: I need to know which
object *instance* is being accessed to report for debugging purposes.
If there's some kind of problem with an object instance, I'd like for
the instance to be able to report, "Hey, this specific thing has
something wrong with it. (As opposed to all the other things of the
same type that you've declared.)" I guess I'm confused as to why
there's so much confusion, the question seems pretty straight-forward,
even if the answer is not.
Nov 30 '07 #8
TonyV wrote:
On Nov 29, 8:58 pm, "John W. Kennedy" <jwke...@attglo bal.netwrote:
>It's easy enough to understand once you accept that he's asking for
something grossly impossible; he wants an object to magically remember
the name of the first variable it was ever assigned to.
--
John W. Kennedy

There's nothing magical about it, and in spite of the condescending
tone of that reply, it's not rocket science what I'm asking.
Yes, there is; and yes, you are. The variable stores but an object
reference, one of maybe many, which may have been created in a number
of different ways.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Nov 30 '07 #9
VK
On Nov 30, 10:02 pm, TonyV <kingskip...@gm ail.comwrote:
I never said I wanted to know which object was being accessed. I've
been consistent in what I need the whole time: I need to know which
object *instance* is being accessed to report for debugging purposes.
You cannot do it - not in JavaScript nor in other languages AFAIK but
my knowledge is limited.
If there's some kind of problem with an object instance, I'd like for
the instance to be able to report, "Hey, this specific thing has
something wrong with it.
For that you have to custom mark each new instance as suggested in my
first post so to report it later.

No other way around. I hope it answers your question.
Nov 30 '07 #10

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

Similar topics

1
2814
by: Jason | last post by:
this is my code and what i get... i'm accessing this through this url http://192.168.0.2/php/test2/test.php?user=me@test.ca&subject=test it grabs the correct stuff from the database, but doesn't put it into flash. this is what i have in the flash file... onClipEvent (load) {
2
2315
by: Steven T. Hatton | last post by:
I find the surprising. If I derive Rectangle from Point, I can access the members of Point inherited by Rectangle _IF_ they are actually members of a Rectangle. If I have a member of type Point in Rectangle, the compiler tells me Point::x is protected. I would have expected Rectangle to see the protected members of any Point. Compiling the following code give me this error: g++ -o rectangle main.cc main.cc: In member function `size_t...
6
2749
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is called "form1", and I have selects called "PORTA", "PORTB" ... etc...
6
5204
by: Alfred B. Thordarson | last post by:
I have a problem accessing a DLL using C#. I'm using C/FRONT with Navision's CFRONT.DLL, which contains the method: DBL_S32* DBL_NextKey(DBL_HTABLE hTable, DBL_S32* Key); typedef signed long int DBL_S32; In addition the documentation says that "hTable" is the "Handle to the table" and "Key" is "A table key or a NULL". Trying to access this
0
1579
by: N. Demos | last post by:
Hello, I'm having problems accessing a complex XML child node (latitude & longitude), and passing it to a function when the XML file has been read into a DataSet. Specifically, the returned object from accessing the 'latitude' and 'longitude' nodes is not a DataTable (as specified in the MSDN). I'm not sure what type is being returned, nor how to go about finding out. Any pointers would be appreciated. Below is the relevent Error message,...
3
5006
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : >************************************************************************ > <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _ > Public Function HelloWorld() As > <System.Xml.Serialization.SoapElementAttribute("return")> String
0
12090
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the likelihood of CRM success from less than 20 percent to 60 percent. WHITEPAPER :
14
3899
by: James Thiele | last post by:
I'd like to access the name of a function from inside the function. My first idea didn't work. >>> def foo(): .... print func_name .... >>> foo() Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 2, in foo
4
3642
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if possible.. for example..i hav a menu in the parent form named "Administrator" whic has an item "mnuLogIn"..now when i click on login..another child form named "frmLogIn" is displayed..what i want to happen is this: when login form(frmLogIn) is...
10
3934
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication eventname string source string ID string
0
9589
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
10593
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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...
0
10085
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...
0
9163
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7626
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
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.