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

<FAQENTRY> 4.41 correction

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 which include an ID attribute where the ID becomes A PROPERTY OF THE GLOBAL WINDOW OBJECT and the scope of the window object is at the bottom of the symbol lookup stack..
In other words, if your design for Microsoft Internet Explorer, you should use the syntax WINDOW.DEVID to avoid name clash and make symbol lookup more efficient.
Chris
Mar 3 '07 #1
6 1484
VK
On Mar 3, 10:18Â*pm, KĹ™ištof Ĺ˝elechovski <giecr...@stegny.2a.plwrote:
At <http://jibbering.com/faq/index.html#FAQ4_41>
SHOULD BE
Microsoft introduced a shortcut that can be used to reference
elements THAT ARE NOT FORM CONTROLS WITHIN A FORM ELEMENT
which include an ID attribute
That is not true for Firefox 1.5 in quirk mode (no appropriate DOCTYPE
switcher). IDed form controls are affected as well by this extension.
A regular payback for trying to monkey out undocumented 3rd party
quirks - high risk to get it either wrong or "too right".

IMHO i) either we leave it as it is as it is better to overcover than
undercover or ii) we are making a quirks table for all browsers up-to-
date emulated the behavior in question.

Which one is the best I don't know. What do you think?
where the ID becomes A PROPERTY OF THE GLOBAL WINDOW OBJECT and the
scope of the window object is at the bottom of the symbol lookup
stack..
There is not such thing as "global window object". There is Global
object representing the current script execution context and there is
window host object which is normally presented and - if presented -
placed before the Global. This way by crafting window properties one
can "shadow" global variables in Global scope, but it is not the best
way. It is better to pre-declare - if possible - all global variables
used in the script by using var statement. This kill the unwanted id -
var echoing.

P.S. For window host object and Global object differences read MSDN
and older topics in this group. For practical demonstration on IE it
requires to create parallel Global scope using behavior. Firefox is
much easier on this matter, something like:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script>

function init() {
alert(typeof txt);
window.txt = true;
alert(typeof txt);
delete(window.txt);
alert(typeof txt);
}

window.onload = init;
</script>
</head>
<body>
<form method="post" action="">
<input type="text" name="txt" id="txt">
</form>
</body>
</html>
Mar 3 '07 #2
VK
On Mar 3, 11:19 pm, "VK" <schools_r...@yahoo.comwrote:
It is better to pre-declare - if possible - all global variables
used in the script by using var statement. This kill the unwanted
id - var echoing.
But first of course use any of mode-switching doctypes, say
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

Then take care of IE by pre-declaring all global variables using var
statement - which is a good programming style anyway.

Mar 3 '07 #3
Křištof Želechovski <gi******@stegny.2a.plwrote:
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.

Mar 3 '07 #4
Richard Cornford said the following on 3/3/2007 5:33 PM:
Kr(ištof Želechovski <gi******@stegny.2a.plwrote:
<snip>
>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?
Speed.

<snip>
>and make symbol lookup more efficient.

The old wives tail
Is it a "wives tail"? My testing tells me differently.
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.
You may want to re-test that with IE7.

/*
Below is just code I used to create a 1000 divs with ID's to copy/paste
into the test page.

for (i=0;i<1000;i++){
document.write('&lt;div id="myDiv' + i + '"&gt;myDiv' + i + '
content&lt;/div&gt;<br>')
}
*/

function testWindow(){
elementToGet = "myDiv" + Math.floor(1000*Math.random())
var start1 = new Date()
for (i=0;i<50000;i++){
var tempVar = window.elementToGet
}
var end1 = new Date()
var totalTime1 = end1-start1
window.results.innerHTML += 'window.ID took '+totalTime1+'milliseconds<br>'
}

function testgEBI(){
var start2 = new Date()
for (i=0;i<50000;i++){
var tempVar = document.getElementById(elementToGet)
}
var end2 = new Date()
var totalTime2 = end2-start2
window.results.innerHTML +=
'document.getElementById(ID) took '+totalTime2+' milliseconds<br>'

}
<button onclick="testWindow()">Test window.ID</button>
<button onclick="testgEBI()">Test getElementById</button>
<div id="results"></div>

<div id="myDiv0">myDiv0 content</div>
<div id="myDiv1">myDiv1 content</div>

rest of div elements here

<div id="myDiv998">myDiv998 content</div>
<div id="myDiv999">myDiv999 content</div>

I am consistently getting results in this range:
window.ID took 265 milliseconds and
document.getElementById(ID) took 22422 milliseconds

Which makes window.ID on the order of 85 times faster than gEBI in IE7.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 4 '07 #5
Randy Webb wrote :
Randy, I've tried to reach Jim and yourself in order to update a few
issues in http://jibbering.com/faq/

4.41 was one item regarding my emails:

The link given in 4.41 should be updated.

http://www.mozilla.org/docs/web-deve...tml#dom_access
should be replaced with
http://developer.mozilla.org/en/docs...th_the_W3C_DOM

Email sent on February 6th 2007
cljfaq home ctvea and net
jim home jibbering and com

Will post the other issues in a distinct post/new thread.

Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)
http://developer.mozilla.org/en/docs...your_Web_Pages
Mar 4 '07 #6
Randy Webb wrote:
Richard Cornford said the following on 3/3/2007 5:33 PM:
>Kr(istof Zelechovski wrote:
<snip>
>>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?

Speed.
Speed is only significant if the reference is to be looked up
sufficiently frequently.
<snip>
>>and make symbol lookup more efficient.

The old wives tail

Is it a "wives tail"? My testing tells me differently.
>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.

You may want to re-test that with IE7.
I would be very surprised if - someGlobalPropertyName - was not also
faster to look up than - window.someGlobalPropertyName - on IE 7.

<snip>
Which makes window.ID on the order of 85 times faster
than gEBI in IE7.
The old wives tail being repeated here was that - window.ID - is faster
to resolve than just - ID -. The relative performance of -
getElementById - is not relevant to that.

Richard.

Mar 4 '07 #7

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

Similar topics

47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
49
$
by: google | last post by:
what dose a $ do in javascript, i have been given a bit of code and there are $'s all over the place, can someone explain their uses
31
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I modify the current browser window?...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.