473,399 Members | 4,177 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.

Dot notation V Bracket notation

Howdy All!

Is there any difference between referencing objects and attributes with dot
notation or bracket notation?

Example,
document.formname.controlname
document [formname] [controlname]

Can I access attributes and objects equally with both?

Thanks for any advice!

Rob
:)
Jul 20 '05 #1
3 4354


Robert Mark Bram wrote:
Howdy All!

Is there any difference between referencing objects and attributes with dot
notation or bracket notation?

Example,
document.formname.controlname
document [formname] [controlname]

Can I access attributes and objects equally with both?

Thanks for any advice!


Member access is defined with the bracket notation but note that inside
the brackets you need an expression which is then evaluated and
converted to a string. Thus above for
document.formname
you need
document["formname"]
as the equivalent bracket notation.
The bracket notation is more flexible as you can put any expression like
a variable in there, the dot notation is shorter but you need to know
member names at coding time and you can only use valid identifiers while
the bracket notation allows arbritrary names e.g.
document["form-name"]


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Howdy Martin,

Thanks for the response!
Member access is defined with the bracket notation but note that inside
the brackets you need an expression which is then evaluated and
converted to a string. Thus above for
document.formname
you need
document["formname"]
as the equivalent bracket notation.
But what about attribute access? Let's say I have a form called "navBar"
with a select called "sites". I can do this:
alert (document [navBar][sites].value);
but not this:
alert (document [navBar][sites][value]);

So bracket notation cannot access attributes right? Or am I missing
something? :)
The bracket notation is more flexible as you can put any expression like
a variable in there, the dot notation is shorter but you need to know
member names at coding time and you can only use valid identifiers while
the bracket notation allows arbritrary names e.g.
document["form-name"]


This is a good point. Thank you.

Rob
:)
Jul 20 '05 #3
I see now...
But what about attribute access? Let's say I have a form called "navBar"
with a select called "sites". I can do this:
alert (document [navBar][sites].value);
but not this:
alert (document [navBar][sites][value]);


alert (document [navBar][sites]["value"]);

Got it.

Rob
:)
Jul 20 '05 #4

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

Similar topics

8
by: Ken in Melbourne Australia | last post by:
If I use the curly bracket syntax (referred to as the complex syntax) within a string, how do I get to call a function within it? The php manual says that the first (or previous) character for...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
3
by: dink | last post by:
helo, I'm new to VS 7.1, searched thru help but no luck. Anyone can tell me a keyboard shortcut to go to the ending bracket when cursor is under opening bracket and vice-versa. I think there...
23
by: Antoon Pardon | last post by:
Now slices are objects in python, I was wondering if slice notation will be usable outside subscribtion in the future. Will it ever be possible to write things like: a = 4:9 for key, value in...
7
by: Sam Kong | last post by:
Hello! My question would not be very practical but just out of curiosity. In JavaScript, Array is a subclass of Object. Well maybe not exactly... but sort of... For normal objects, you can...
3
by: scunnybunny | last post by:
What I am trying to do is get the program to look along the array and if the first letter is ‘T’ and the last letter ‘M’ (10P7-TXL/) on the highlighted piece of tax code. #write tax bracket 1 ...
11
by: -Lost | last post by:
I was perusing some code and saw: var theForm = document.forms; if (!theForm) { theForm = document.aspnetForm; } Is this a waste of code? Or is there some instance where bracket notation...
13
by: Martin Drautzburg | last post by:
This may be pretty obvious for most of you: When I have an object (an instance of a class "Foo") I can access attributes via dot notation: aFoo.bar however when I have a dictionary aDict...
5
by: johnnash | last post by:
typedef astruct { int x; } A; struct b { A a;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
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...
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
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.