Re: <FAQENTRY> 4.41 correction
- From: "Richard Cornford" <Richard@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 3 Mar 2007 22:33:49 -0000
Křištof Želechovski <giecrilj@xxxxxxxxxxxx> wrote:
At <http://jibbering.com/faq/index.html#FAQ4_41>
IS
Microsoft introduced a shortcut that can be used to reference
elements which include an ID attribute where the ID becomes a
global variable.
SHOULD BE
Microsoft introduced a shortcut that can be used to reference
elements THAT ARE NOT FORM CONTROLS WITHIN A FORM ELEMENT
In the context of question answered in the FAQ that is an inconsequential detail. (There is no sense in telling someone about never being able to reference a particular from of IDed element by Identifier when they are asking why accessing IDed elements by Identifier does not work in all environments.)
which include an ID attribute where the ID becomes A PROPERTY
OF THE GLOBAL WINDOW OBJECT
The only practical distinction between a global variable and a property of the global object is that a property of the global object can be deleted and a global variable cannot be deleted. The properties of the global object that result form IDed elements in the document on IE cannot be deleted.
and the scope of the window object
Objects do not have scopes, only functions and execution contexts have them.
is at the bottom of the symbol lookup stack..
The global object is at the end of all scope chains. ('lookup stack' has no meaning in ECMAScript).
In other words, if your design for Microsoft Internet
Explorer, you should use the syntax WINDOW.DEVID
Should you? What is wrong with using - document.getElementById("DEVID") -, as that works fine in IE as well as other browsers?
to avoid name clash
You would only risk a naming clash if making the reference from an execution context that had an object on its scope chain that had a property named "DIVID, which would itself be symptomatic of inappropriate code design (with regard to variable/property naming).
and make symbol lookup more efficient.
The old wives tail that qualifying property accessors in IE with - window - makes resolving them faster has been demonstrated false often enough by now to make repeating it in public a poor idea.
Richard.
.
- Follow-Ups:
- Re: <FAQENTRY> 4.41 correction
- From: Randy Webb
- Re: <FAQENTRY> 4.41 correction
- References:
- <FAQENTRY> 4.41 correction
- From: Křištof Želechovski
- <FAQENTRY> 4.41 correction
- Prev by Date: Re: Question about Javascript classes and execution
- Next by Date: Re: Time/distance converter help (ptII)
- Previous by thread: Re: <FAQENTRY> 4.41 correction
- Next by thread: Re: <FAQENTRY> 4.41 correction
- Index(es):
Relevant Pages
|