Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > Name of class i...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 9 Topic 35490 of 36205
Post > Topic >>

Name of class instance

by Matthias Watermann <lists@[EMAIL PROTECTED] > May 6, 2008 at 09:31 AM

Hi,

I'm wondering if it's possible for an object to figure it's name.
for example:

function baseClass() {
	// setup properties of "baseClass"
}
baseClass.prototype = {
	aMethod: function() {
		// do something using the name of the object
		// that's an instance of this (or derived) class
		// e.g.
		// window.alert('my name is: "' + DUNNO + '"');
	};
};

function childOne() {
	// setup properties of "childOne"
}
childOne.prototype = new baseclass();

function childTwo() {
	// setup properties of "childTwo"
}
childTwo.prototype = new baseclass();

var o1 = new childOne(), o2 = new childTwo();

Now when calling "o1.aMethod()" the "DUNNO" should be "o1" and the
same with "o2" respectively.

Is that possibly without having to force a "name" argument down the
inheritance tree?

-- 
	Matthias
    /"\
    \ /    ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
     X                           - AGAINST M$ ATTACHMENTS
    / \
 




 9 Posts in Topic:
Name of class instance
Matthias Watermann <li  2008-05-06 09:31:19 
Re: Name of class instance
Henry <rcornford@[EMAI  2008-05-06 03:05:30 
Re: Name of class instance
VK <schools_ring@[EMAI  2008-05-06 03:09:03 
Re: Name of class instance
Matthias Watermann <li  2008-05-06 13:25:21 
Re: Name of class instance
Thomas 'PointedEars' Lahn  2008-05-06 21:46:55 
Re: Name of class instance
VK <schools_ring@[EMAI  2008-05-06 05:00:58 
Re: Name of class instance
Matthias Watermann <li  2008-05-06 15:17:07 
Re: Name of class instance
sheldonlg <sheldonlg&g  2008-05-06 10:48:00 
Re: Name of class instance
Matthias Watermann <li  2008-05-06 17:51:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 7:18:14 CDT 2008.