473,612 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any instance where bracket notation might fail?

I was perusing some code and saw:

var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnet Form;
}

Is this a waste of code? Or is there some instance where bracket notation might fail?

-Lost
Apr 20 '07 #1
11 2385
On 20 Apr, 15:29, "-Lost" <missed-s...@comcast.ne twrote:
I was perusing some code and saw:

var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnet Form;

}

Is this a waste of code? Or is there some instance where bracket notation might fail?

-Lost
It might fail in any circumstance where the form HTML itself is
dynamically generated, depending on timing.

Apr 20 '07 #2
"Sean Inglis" <in*****@gmail. comwrote in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
On 20 Apr, 15:29, "-Lost" <missed-s...@comcast.ne twrote:
>I was perusing some code and saw:

var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnet Form;

}

Is this a waste of code? Or is there some instance where bracket notation might fail?
>
It might fail in any circumstance where the form HTML itself is
dynamically generated, depending on timing.
Hrmm... if that were the case then the dot notation version would fail as well.

-Lost
Apr 20 '07 #3
Lee
-Lost said:
>
"Sean Inglis" <in*****@gmail. comwrote in message
news:11******* *************** @y80g2000hsf.go oglegroups.com. ..
>On 20 Apr, 15:29, "-Lost" <missed-s...@comcast.ne twrote:
>>I was perusing some code and saw:

var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnet Form;

}

Is this a waste of code? Or is there some instance where bracket notation might
fail?
>>
It might fail in any circumstance where the form HTML itself is
dynamically generated, depending on timing.

Hrmm... if that were the case then the dot notation version would fail as well.
Bracket notation is more reliable than dot notation, because dot
notation would fail if you also had a global variable or function
named "aspnetForm " (unlikely in this case, of course).
--

Apr 20 '07 #4
-Lost said the following on 4/20/2007 10:29 AM:
I was perusing some code and saw:

var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnet Form;
}

Is this a waste of code?
Yes.
Or is there some instance where bracket notation might fail?
If bracket notation won't work then dot notation sure isn't going to
work either.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 20 '07 #5
"Randy Webb" <Hi************ @aol.comwrote in message
news:ue******** ************@gi ganews.com...
-Lost said the following on 4/20/2007 10:29 AM:
>I was perusing some code and saw:

var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnet Form;
}

Is this a waste of code?

Yes.
Thought so.
>Or is there some instance where bracket notation might fail?

If bracket notation won't work then dot notation sure isn't going to work either.
Thought so.

Thanks!

-Lost
Apr 20 '07 #6
-Lost wrote:
>I was perusing some code and saw:

var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnet Form;
}

Is this a waste of code? Or is there some instance where
bracket notation might fail?
Your question betrays some misconception, either as to the nature of
property accessors or about what the code above is attempting.

Bracket notation and dot notation are the two forms of property accessor
available in javascript. Whenever the property names used in either are
literals that would qualify as Identifiers in javascript the two are
completely interchangeable . That is:-

document.forms['aspnetForm']

- may also be written as any of:-

document.forms. aspnetForm
document['forms'].aspnetForm
document['forms']['aspnetForm']
window['document'].forms.aspnetFo rm
window['document'].forms['aspnetForm']
window['document']['forms'].aspnetForm
window['document']['forms']['aspnetForm']

- to precisely the same effect (though with some very minor differences
in performance).

And similarly:-

document.aspnet Form

- may also be written as:-

document['aspnetForm']
window['document'].aspnetForm
window['document']['aspnetForm']

- to precisely the same effect.

The code above has no interest in any distinction between dot notation
property accessors and bracket notation property accessors, and that
distinction had no relevance for the code.

The question the code is asking is "is there a property of the -
document.forms - collection with the name 'aspnetForm'?", and if not "is
there then instead a property of the - document - with the same name?".

It almost certainly is a waste of code because if you assume that a
property with the name "aspnetForm " is intended to refer to a form
element (the alternative would be to assume the author did not perceive
the sense in giving objects non-misleading names) then there have never
been any browsers where a named form element could not be references as
a named property of the (ancient, and W3C DOM formalised) -
document.forms - collection but could then be referenced through the
common (though non-standard) HTML DOM shortcut of referring to it as a
named property of the - document - object.

Richard.

Apr 29 '07 #7
Richard Cornford wrote:
It almost certainly is a waste of code because if you assume that a
property with the name "aspnetForm " is intended to refer to a form
element (the alternative would be to assume the author did not perceive
the sense in giving objects non-misleading names) then there have never
been any browsers where a named form element could not be references as
a named property of the (ancient, and W3C DOM formalised) -
document.forms - collection but could then be referenced through the
common (though non-standard) HTML DOM shortcut of referring to it as a
named property of the - document - object.
For application/xhtml+xml documents Mozilla has it the other way,
document.forms. formName is implemented but document.formNa me is not:
<http://home.arcor.de/martin.honnen/javascript/test2007042901. xhtml>

So in the case of application/xhtml+xml the code

var theForm = document.aspnet Form;
if (!theForm) {
theForm = document.forms['aspnetForm'];
}

would make some sense but simply doing

var theForm = document.forms['aspnetForm'];

would suffice.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 29 '07 #8
Martin Honnen wrote:
Richard Cornford wrote:
>It almost certainly is a waste of code because if you assume
that a property with the name "aspnetForm " is intended to
refer to a form element (the alternative would be to assume
the author did not perceive the sense in giving objects
non-misleading names) then there have never been any browsers
where a named form element could not be references as a named
property of the (ancient, and W3C DOM formalised) - document.forms -
collection but could then be referenced
through the common (though non-standard) HTML DOM shortcut of
referring to it as a named property of the - document - object.

For application/xhtml+xml documents Mozilla has it the other way,
document.forms. formName is implemented but document.formNa me is not:
<http://home.arcor.de/martin.honnen/javascript/test2007042901. xhtml>
Which was my reason for stating "HTML DOM shortcut", to imply the
possible non-applicability/availability of those shortcuts in XHTML
DOMs.

I suppose that because most of the people who think that they are
working with XHTML are just deluding themselves and actually working
with (error-filled tag-soup) HTML, it may be worth being more explicit
about the distinction between those two types of DOM. Though it has been
said often enough in the past that the current apparently pandemic
failure to see the distinction seems wilful.
So in the case of application/xhtml+xml the code

var theForm = document.aspnet Form;
if (!theForm) {
theForm = document.forms['aspnetForm'];
}

would make some sense but simply doing

var theForm = document.forms['aspnetForm'];

would suffice.
Absolutely.

Richard.

Apr 29 '07 #9
Richard Cornford wrote:
I suppose that because most of the people who think that they are
working with XHTML are just deluding themselves and actually working
with (error-filled tag-soup) HTML, it may be worth being more explicit
about the distinction between those two types of DOM.
Any links to a more complete discussion of this?

--
C.W.Holeman II | cw***@Julian5Lo cals.com-5 http://JulianLocals.com/cwhii
To only a fraction of the human race does God give the privilege of
earning one's bread doing what one would have gladly pursued free, for
passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks
Apr 30 '07 #10

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

Similar topics

8
6830
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 the curly bracket has to be a dollar sign '$'. This is fine for variables, arrays and some objects but doesn't allow me to call a function such as addslashes() or trim() before I return the string in the variable.
3
4369
by: Robert Mark Bram | last post by:
Howdy All! Is there any difference between referencing objects and attributes with dot notation or bracket notation? Example, document.formname.controlname document Can I access attributes and objects equally with both?
102
5644
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 can't tell where a bracket is missing.... a few weeks have past, I requested a feature for the delphi ide/editor "automatic identation of code in begin/end statements etc" and today when I woke up I suddenly released a very simple solution for this...
3
7258
ashsa
by: ashsa | last post by:
Hi everyone, I am trying to display a numeric value fetched from an sql server table which is stored in the exponential notation. For eg, 0.08 is getting stored in the table as 8.0000000000000002E-2. This causes the xslt function format-number() to fail. I use it as <xsl:value-of select='format-number(8.0000000000000002E-2, "###,###.00")' /> The message says that This name may not contain the '#' character: -->#<--##,###.00...
0
8173
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8617
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...
1
8254
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8422
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
7044
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
6082
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
4047
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1699
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1416
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.