473,396 Members | 1,814 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,396 software developers and data experts.

Client-side DOM: are 'window' and 'document' real objects?

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 user-created objects and object literals in both Netscape
and IE (as expected).

Thus it appears that 'window' and 'document' do not act like normal objects.

Also, under IE 'window' and 'document' do not have constructor properties,
whereas in Netscape they are defined as 'Window' and 'HTMLDocument'
respectively. This seems particularly strange since even object literals
have a constructor property (in both browsers).

1) Is this the correct behavior for the 'window' object?
2) Is the Netscape or IE behavior correct for the 'document' object?
3) Can anyone point me to appropriate documentation for the behavior or
these objects?

Below is an HTML page which demonstrates this behavior.

If anyone could shed any light on what is going on here (or point me to a
good resource), I would be very grateful.

Thank you.
<html>
<head>
<title>window object test</title>
<script type="text/javascript">
function showInfo() {
var dateObject = new Date();
var literalObject = {x:1, y:2};
alert("window.constructor = " + window.constructor);
// 'undefined' in IE, 'Window' in Netscape
alert("document.constructor = " + document.constructor);
// 'undefined' in IE, 'HTMLDocument' in Netscape
alert("dateObject.constructor = " + dateObject.constructor);
// 'Date' in both browsers
alert("literalObject.constructor = " + literalObject.constructor);
// 'Object' in both browsers
Object.prototype.testProperty = "Hello";
alert("window.testProperty = " + window.testProperty);
// 'undefined' in IE and Netscape
alert("document.testProperty = " + document.testProperty);
// 'undefined' in IE, "Hello" in Netscape
alert("dateObject.testProperty = " + dateObject.testProperty);
// 'Hello' in both browsers
alert("literalObject.testProperty = " + literalObject.testProperty);
// 'Hello' in both browsers
}
</script>
</head>
<body onload="showInfo();">
<h3 align="center">window object test</h3>
</body>
</html>
Jul 20 '05 #1
3 1796
"Hermit Crab" <he********@att.net> wrote in message
news:vX***********************@bgtnsc04-news.ops.worldnet.att.net...
<snip>
Thus it appears that 'window' and 'document'
do not act like normal objects.
The ECMA 262 3rd Edition specification would categorise document (and
all of the DOM elements/nodes under it) as a "Host Objects" (section
4.3.8) and makes no requirements of host objects. On web browsers the
window object is also the object that ECMA 262 refers to as the global
object (Section 15.1) and the global object is specified as having no
[[Constructor]] property and implementation dependent [[Prototype]] and
[[Class]] properties.

<snip>1) Is this the correct behavior for the 'window' object?
Yes, in so far as it is not incorect.
2) Is the Netscape or IE behavior correct for the
'document' object?
The only criteria of correctness available for the document object are
the W3C Core and HTML DOM specifications and Netscape 6+ and IE 5.5+
more or less conform to that specification in their implementations.
But the W3C DOM specifications define interfaces and say nothing about
prototypes, constructors or inheritance (because they are intended to be
language neutral).
3) Can anyone point me to appropriate documentation for
the behavior or these objects?

<snip>

ECMA 262 and the W3C DOM specifications are referenced in the
comp.lang.javascript FAQ:-

<URL: http://jibbering.com/faq/ >

Richard.
Jul 20 '05 #2
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:br*******************@news.demon.co.uk...
The ECMA 262 3rd Edition specification would categorise document (and
all of the DOM elements/nodes under it) as a "Host Objects" (section
4.3.8) and makes no requirements of host objects.


<snip of extremely helpful reply>

Thanks very much for you reply. I took a look at the sections of ECMA-262
that and would like to verify that I'm understanding it correctly. It seems
that:

1) Host objects may, but are not required to inherit functionality from
Object.

2) Attempting at add functionality to any 'host' object via the prototype
property of the constructor should be avoided. Depending upon the
implementation, the updates to the prototype property may not be allowed.
Adding properties to a prototype should only be done for user-defined
objects and those specified in ECMA-262.

Have I interpreted you response correctly?

In any event, you've pointed me in the right direction. I hadn't really
been aware of the differences between 'host' and 'native' objects. I'll go
back and do some more reading.

Thanks for taking the time to help me.
..

Jul 20 '05 #3
"Hermit Crab" <he********@att.net> wrote in message
news:4C***********************@bgtnsc04-news.ops.worldnet.att.net...
<snip>
... . It seems that:

1) Host objects may, but are not required to inherit
functionality from Object.
Yes.
2) Attempting at add functionality to any 'host' object
via the prototype property of the constructor should be
avoided.
That might be a bit strong. Generally I would tend to avoid modifying
the prototype of host objects (if available) but if handled with the
caution that is required in any reliable client-side script it could be
a more efficient alternative to a less direct method.

Though I don't see much point in modifying the document or the window
via their prototypes as there is only one of each and they can be
modified directly with the same effort.
Depending upon the implementation, the updates to the
prototype property may not be allowed.
Yes, and there may be no publicly accessible prototype property or
constructor.
Adding properties to a prototype should only be done for
user-defined objects and those specified in ECMA-262.
User-defined objects are certainly where this type of functionality can
be expected to work reliably.
Have I interpreted you response correctly?

<snip>

Yes.

Richard.
Jul 20 '05 #4

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

Similar topics

2
by: news.microsoft.com | last post by:
Hi I write dll library which one of it component will be Net socket communication. Communication is working very good, but i've got problem when client is connecting. When server is started,...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
2
by: Raquel | last post by:
How do I know whether the 'runtime client' and the 'application development client' are installed on my machine? When I issue the command "db2licm -l", it gives the following output: Product...
0
by: Tim Northrup | last post by:
Help! We have DB2 V7.2 (fixpak 12) installed on Windows2003 Server, and the latest V7.2 client installed on another system. The DB2CODEPAGE on all systems is set to 1208, and the database was...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
13
by: Sandeep Singh | last post by:
I am making socket client application in C# how can i get ip address of client who has connected to server
14
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
2
by: Frank Swarbrick | last post by:
I am trying to understand "client authentication" works. My environment is DB2/UDB LUW 8.2 on zSeries SLES9 as the database server and DB2 for VSE 7.4 as the client. We currently have DB2/LUW set...
0
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...

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.