473,699 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

window object

yb
Hi,

Is there a standard for the global 'window' object in browsers? For
example, it supports methods such as setInterval and clearInterval, and
several others.

I know that w3c standardized several parts of the DOM, but this does
not include the window object.

Thank you

Mar 2 '06 #1
26 5680
yb wrote:
Hi,

Is there a standard for the global 'window' object in browsers? For
example, it supports methods such as setInterval and clearInterval, and
several others.
The window object is not part of either the ECMAScript Language or W3C
Document Object Model (DOM) specification - it belongs to DOM Level 0,
which is described in the introduction to the W3C DOM 1 specification as:

'The term "DOM Level 0" refers to a mix (not formally specified)
of HTML document functionalities offered by Netscape Navigator
version 3.0 and Microsoft Internet Explorer version 3.0. In some
cases, attributes or methods have been included for reasons of
backward compatibility with "DOM Level 0".'

<URL:http://www.w3.org/TR/REC-DOM-Level-1/level-one-html.html#ID-1176245063>
You will find references to the window object in the Gecko DOM reference:
<URL:http://developer.mozil la.org/en/docs/DOM:window>

and MSDN's 'HTML and DHTML' documentation:
<URL:http://msdn.microsoft. com/workshop/author/dhtml/reference/objects/obj_window.asp>
The global object is a concept of the ECMAScript Language (colloquially
known as 'JavaScript', which is a registered trademark of Sun
Microsystems, Inc.), see section 10.1.5 of the specification.

In user agents that have a concept of a window object, it is synonymous
with the global object. When explaining the global object, the above
reference says:

"...in the HTML document object model the window property of
the global object is the global object itself."
You can test whether that is true - 'this' outside any other context
refers to the global object:

var Global = this;

Now 'Global' refers to the global object. To check that it refers to
the same object as window:

alert( Global === window ); // shows 'true'
I guess it's possible that somewhere there is an ECMAScript environment
that implements a window object that isn't the global object. It's more
likely you'll find one that doesn't have a window object at all (but it
must have a global object if compliance matters).

I know that w3c standardized several parts of the DOM, but this does
not include the window object.


Generally there is no need to reference the window object. If there is
a circumstance that you feel 'window' should be included in a reference,
but are uncertain whether the environment supports a window object, then
use the abovementioned 'Global' variable, e.g.

var Global = this;

function someFn(){
...
Global.setTimeo ut(...);
...
}
Some believe that a fully qualified reference (e.g. window.setTimeo ut())
makes scripts run faster as it reduces the time spent on scope chain
resolution - I have never tried to confirm whether that is true or not.
--
Rob
Mar 3 '06 #2
RobG <rg***@iinet.ne t.au> writes:
I guess it's possible that somewhere there is an ECMAScript
environment that implements a window object that isn't the global
object.
The Adobe SVG plugin, IIRC.
It has a window object, but it is not the global object.

Also note that the SVG specification is trying to formalize
some parts of DOM 0.
Some believe that a fully qualified reference
(e.g. window.setTimeo ut()) makes scripts run faster as it reduces the
time spent on scope chain resolution - I have never tried to confirm
whether that is true or not.


It should be false. In fact is should run slower, if anything.
The global "window" variable name is no different form "setTimeout ".
Both must be looked up in the same scope chain, ending at the global
object. After that, "window.setTime out" will do one further property
lookup on the global object, so it should take longer than just using
"setTimeout " directly.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Mar 3 '06 #3
VK

Lasse Reichstein Nielsen wrote:
It should be false. In fact is should run slower, if anything.
The global "window" variable name is no different form "setTimeout ".
Both must be looked up in the same scope chain, ending at the global
object. After that, "window.setTime out" will do one further property
lookup on the global object, so it should take longer than just using
"setTimeout " directly.


It is not true at least for IE 5.0 or higher and Opera 8.0 or higher -
thus for 80%-90% of the browsers on the market (grace to IE). Therefore
ECMA-compliant scope schema will be rather a rare exeption than a rule
with your visitors. One can hate it, scream and cry about it :-) - but
at least she should be aware of it.

For IE and Opera "Global" object and "window" object constitute two
distinct programming scopes. Again I'm not talking about some
occasional models like Adobe SVG plugin or such.
I'm talking about the standard environment of a HTML page (XHTML is not
supported by IE and interpreted as regular HTML) with a script running
on it.

In such case we have Global scope (level of global variables ang Global
methods like escape, encodeURI etc.) and Window scope *above* it (level
of ID'entified HTML elements and window methods like setTimeout, open
etc.)

On lookup the engine search first in the Global scope, if not found
then in the window scope.

Therefore if we say declare
var setTimeout = 'foobar';
we shadow window.setTimeo ut reference (engine will find "setTimeout " in
the Global scope first thus will never look in the window scope above).

Respectively if we declare:
window['foo'] = 'bar';
and later call alert(foo) then
engine will look first in the Global scope, fail on it, then look in
the window scope and find it.

For a non-aware user the fact that:
window['foo'] = 'bar';
alert(foo); // 'bar'
may lead to the conclusion that Global scope and window scope are the
same - but nothing more far from the true than that, again - at least
for IE and Opera.

It also explain the real mechanics of possible circular reference leaks
in IE as well as explains the overall higher memory consumption by
JScript - which is *not* a memory leak but makes nervious many
developers, specially ones coming from a C++ or so background.

As I'm kind of tired of regular hysterics about "VK unbellyfeels ECMA":
here a sample and I don't care if it trigs the thinking process or the
doublethink will help as usual.
....
<script type="text/javascript">
var v1 = true;

function demo() {
var v2 = true;
alert(v1);
alert(v2);
alert(this[v2]);
alert(v3);
}

window.onload = demo;
</script>
....
<div id="v1">v1</div>
<div id="v2">v2</div>
<div id="v3">v3</div>
....

P.S. If it helped to start the thinking process (which I still hope
despite don't care too much anymore):- the next question would be: "Is
it possible and how in IE's scope model that a DOM object is still
referenced in the execution context - thus not GC-available - despite
no one JScript variable holds a reference to it?"

Mar 3 '06 #4
RobG wrote:
[...]
The global object is a concept of the ECMAScript Language (colloquially
known as 'JavaScript', which is a registered trademark of Sun
Microsystems, Inc.), see section 10.1.5 of the specification.

In user agents that have a concept of a window object, it is synonymous
with the global object. When explaining the global object, the above
reference says:

"...in the HTML document object model the window property of
the global object is the global object itself."
However, this is not a normative statement.

You have already pointed out that "the window object" is not specified in
ECMAScript or the W3C DOM. But to be absolutely clear about this: The
above non-normative statement originates from ECMAScript Edition 1 (June
1997) where it referred to "(the) HTML (document object model)" of the
only user agents that implemented ECMAScript: Netscape Navigator (with
JavaScript), and Internet Explorer (with JScript). (Most notably, in
JavaScript there had been no separation between core language and
[Netscape] DOM/AOM before JavaScript 1.4 [1999].) It certainly was not
intended to refer to the W3C Document Object Model HTML specifications
(the earliest draft of W3C DOM Level 1 HTML dated 1997-10-09). The term
"HTML" has been changed to "the HTML document object model" in ECMAScript
Edition 3 (December 1999), probably to distinguish between the markup
language and the object model used to access the element tree created
when it is parsed.
You can test whether that is true - 'this' outside any other context
refers to the global object:

var Global = this;

Now 'Global' refers to the global object. To check that it refers to
the same object as window:

alert( Global === window ); // shows 'true'


Your logic is flawed, because the `window' property of the Global object
refers to a host object which does not need to strictly implement
ECMAScript algorithms, including the algorithm for the `===' operator.

Given the above strict comparison, it could as well be, and would strictly
conform to the ECMAScript specification, that the Global Object and the
object referred to by its host-defined `window' property are different
objects; that the properties of the object referred to by the `window'
property of the Global Object are also host-defined properties of the
Global object that are added to it before execution context is entered;
that every augmentation of the host object referred to with the `window'
property of the Global Object includes augmentation of the Global Object
(and vice-versa) through language-specific conforming extensions to the
ECMAScript specification. It has been showed already here that there is a
host object that implements the `==' operation different than specified.
PointedEars
Mar 3 '06 #5
VK

RobG wrote:
In user agents that have a concept of a window object, it is synonymous
with the global object.
I'm aware of only one browser where this is true: Firefox. "Bravo
Firefox!" etc. but with the current share of actions this standard
behavior is rather non-standard on the web-wide run.
When explaining the global object, the above
reference says:

"...in the HTML document object model the window property of
the global object is the global object itself."
While MSDN says: "For client versions of JScript, this refers to the
window object if used outside of the context of any other object."
However non-standard it may be, it is implemented exactly as
documented.

You can test whether that is true - 'this' outside any other context
refers to the global object:

var Global = this;

Now 'Global' refers to the global object. To check that it refers to
the same object as window:

alert( Global === window ); // shows 'true'


Again: this test does what expected only for Firefox. In IE you simply
getting a reference to the window and then compare window===window with
is naturally true. Global object is escaping this test. See my post in
this thread for the correct test demonstrating that Global and Window
are different objects with separate scopes.
Moreover IE distincts "The Window" (the global context atop of Global
object) and "the window" (surrent window where the script is
executing). Therefore "window" object is "The Window" while window.self
is "the window". IE needs it as it implements additional current window
scope for constructors. Say you cannot create a new instance using
constructor located in another frame (it will be "Cannot use freed
script" error).

Overall there is much more of mechanics here than one sencence from
Books of ECMA. And actually Books of ECMA is the least informative
source to look at *for this particular question*. ;-)

Just another chunk to think about (feel free to experiment further)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html401/strict.dtd">
<html>
<head>
<title>Global vs. Window</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<style type="text/css">
body { background-color: #FFFFFF}
</style>

<script type="text/javascript">
/* Test 1 */
alert(this === window);
alert(this === window.window);
alert(this === self);
alert(window === self);

// IE 6.0
// true
// false
// false
// false

// Opera 8.51
// false
// false
// false
// true

// Firefox 1.5.0.1
// true
// true
// true
// true

function demo() {
/* Test 2 */
var alert = function(m) {window.alert(m +'bar');}
alert('foo'); // 'foobar'
window.alert('f oo'); // 'foo'
}

window.onload = demo;
</script>

</head>

<body>

<div id="v1">v1</div>
<div id="v2">v2</div>
<div id="v3">v3</div>

</body>
</html>

Mar 4 '06 #6
VK
> >RobG wrote:
In user agents that have a concept of a window object, it is synonymous
with the global object.
VK wrote:
I'm aware of only one browser where this is true: Firefox.


Actually it is not true for Firefox neither: they just tryed to *mimic*
that ECMA statement as hard as they could, so it's really difficult to
catch them on the act :-)

Nevertheless the test #2 from my previous post gets them - I just
didn't check it first on Firefox:

function demo() {
/* Test 2 */
var alert = function(m) {window.alert(m +'bar');}
alert('foo'); // 'foobar'
window.alert('f oo'); // 'foo'
// Gocha! :-)
}

Mar 4 '06 #7
On 04/03/2006 14:12, VK wrote:
function demo() {
/* Test 2 */
var alert = function(m) {window.alert(m +'bar');}
alert('foo'); // 'foobar'
window.alert('f oo'); // 'foo'
// Gocha! :-)
}


That doesn't prove anything, except that /you/ are unbelievably incompetent.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Mar 4 '06 #8
VK

Michael Winter wrote:
On 04/03/2006 14:12, VK wrote:
function demo() {
/* Test 2 */
var alert = function(m) {window.alert(m +'bar');}
alert('foo'); // 'foobar'
window.alert('f oo'); // 'foo'
// Gocha! :-)
}


That doesn't prove anything, except that /you/ are unbelievably incompetent.


As I said: whatever.

P.S.
<script type="text/javascript">
var alert = function(m){win dow.alert('bar' );}
(this.alert('fo o'));

// 'foo'
// 'bar'
</script>

Mar 4 '06 #9
VK wrote:
Michael Winter wrote:
On 04/03/2006 14:12, VK wrote:
> function demo() {
> /* Test 2 */
> var alert = function(m) {window.alert(m +'bar');}
> alert('foo'); // 'foobar'
> window.alert('f oo'); // 'foo'
> // Gocha! :-)
> }


That doesn't prove anything, except that /you/ are unbelievably <-.
incompetent. |

|
As I said: whatever. |
|
P.S. |
<script type="text/javascript"> |
var alert = function(m){win dow.alert('bar' );} |
(this.alert('fo o')); |
|
// 'foo' |
// 'bar' |
</script> |

|
---------------------------------------------------------------------'
PointedEars
Mar 4 '06 #10

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

Similar topics

3
1837
by: Hermit Crab | last post by:
I'm seeing some unexpected (at least to me) behavior in the 'window' and 'document' objects under Netscape 7.1 and Internet Explorer 6.0. When a property is added to the prototype for 'Object', it was my understanding that it should be visible to all objects. But it appears that it is NOT visible in the 'window' object of either IE or Netscape. It is visible in the 'document' property of Netscape, but not IE. It is visible in...
31
2839
by: Benno Bös | last post by:
If I use the following construct in the frame "main" for a link to an extern site: <A HREF="http://www.any.xy" TARGET="extern"> the Browser is creating the window "extern", loading the page www.any.xy an setting the focus to "extern". But when I go return to "main" without closing "extern", a click to an other link (e.g. www.2nd_any.xy) on "main" does not setting the focus to "extern".
32
2499
by: Eli | last post by:
How can I POST a form into a new window where I control the size and other attributes of the new window? Also. Are there any implications, perhaps due to browser security (Interne Explorer?) that could cause problems if I try to post a form at www.mydomain.com to www.anotherdomain.com?
10
3074
by: soup_or_power | last post by:
The pop up window has several checkboxes. I'm unable to access the checkboxes using the handle from window.open. Any way to do this? var display; function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) { display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=150,width=190')
12
1896
by: Bonj | last post by:
i'm trying to create a class that will contain all the features of instantiating a window and showing it. I've got the SetWindowLong / GetWindowLong pair to succesfully store the 'this' pointer in the hWnd's GWL_USERDATA, but the pointer that it's referring to always seems to point to the base class and never the derived class. I don't know what I'm doing wrong, this has been driving me mad for hours. Consequently, the static WndProc...
1
11574
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
4
6404
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database to look a and I am loosing tremendious amounts of time trying to organize it so that I could view it. Regards, Alexandre Brisebois
2
2146
by: KC | last post by:
Hi, Every JavaScript executive context has a top-level window and we can use window.open() to open another window ... Does this related to Windows created by click on "File"->"New Window" or "File" -"New Tab" in browser's menu bar ? I think window created by "File"->"New Window" and "File"->"New Tab" are independent to each other from JavaScript's point of view. Is this correct ?
24
8214
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and seems to have a (tiny) amount overhead since window itself points to the global object, hence, a circular reference. (From everything I am reading, window is just a REFERENCE back to the global object, as opposed to a separate object.)
0
9172
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
8908
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
8880
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
7745
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
6532
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
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
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.