473,399 Members | 2,858 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,399 software developers and data experts.

Constructor Function: Listing names of attributes in the structure

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
2 1155
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Olivier Lefevre | last post by:
Python 2.3 >>> def foo(): .... foo.a = 1 .... >>> vars(foo) {} >>> foo() >>> vars(foo) {'a': 1} >>>
8
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
8
by: Lüpher Cypher | last post by:
Hi, Suppose we have a hierarchical class structure that looks something like this: Object | +-- Main | +-- Object1
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
13
by: shsingh | last post by:
I have a class A containing some map as data variables. I creat an object of class A on heap by allocatiing memory by using "malloc". This will return me the required memory but the object is not...
11
by: Rimpinths | last post by:
I'm new at developing user controls in C#, and one thing I've noticed right off the bat is that the constructor gets called twice -- once at design time, once at run time. In short, I'm trying...
10
by: SQL Server | last post by:
I am writing a function which will take two parameters. One the field to be returned from a table and second parameter is the ID of the record to be returned. Problem is it's not returning the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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,...
0
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...

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.