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>