By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,481 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,481 IT Pros & Developers. It's quick & easy.

Constructor Function: Listing names of attributes in the structure

P: n/a
If I create an object using a constructor function, and then specify
attributes using the format "this.attrib1 = 123;" - then it is easy
enough to list the VALUES (using a loop like "for thisAttrib in
thisObject"), but for faster debugging, I would like also to be able
to list the NAMES of the attributes using a similar loop.

Is there a way to reference the attribute name specified in the
"this." statement,
ie the "attrib1" bit of "this.attrib1 = 123;" ?

John Geddes

Jun 14 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jun 14, 2:07 am, John Geddes <j...@starmarkassociates.co.ukwrote:
If I create an object using a constructor function, and then specify
attributes using the format "this.attrib1 = 123;" - then it is easy
enough to list the VALUES (using a loop like "for thisAttrib in
thisObject"), but for faster debugging, I would like also to be able
to list the NAMES of the attributes using a similar loop.

Is there a way to reference the attribute name specified in the
"this." statement,
ie the "attrib1" bit of "this.attrib1 = 123;" ?
Not quite sure if this is what you're looking for,
but here's is one of my debugging routines:

function DebugObject(a)
{
for(var b in a)
DebugOutput('\n'+ b + ':' +a[b]);
}

----
Geoff

Jun 14 '07 #2

P: n/a
On 14 Jun, 07:50, Geoffrey Summerhayes <sumr...@gmail.comwrote:
function DebugObject(a)
{
for(var b in a)
DebugOutput('\n'+ b + ':' +a[b]);

}
Thanks - perfect.

John Geddes
Jun 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.