views:

203

answers:

1

Below javascript has different effect in different browsers.

document.write(this.location.constructor);
document.write("<br/>");
document.write(this.constructor);
document.write("<br/>");

In Chrome, the page has

function Location() { [native code] }
function DOMWindow() { [native code] }

In Firefox, the page has

[object Location]
[object Window]

In IE8, the page has

undefined
undefined

The difference between Chrome and Firefox might be different toString() implementation. I just cannot understand why the two objects' constructors are undefined in IE. If their constructors are undefined, what about their prototypes? also undefined?

+1  A: 

Using the IE8 debugging console, I have no problems using the code you gave as an example.

My results...

[object Location]
[object Window]

Are you sure that something else is not causing these to fail?

StingyJack
I'm using IE 8.0.6001.18372. Interestingly, if I load one local html with "document.write(this.constructor)", it is undefined; if I just type "javascript:this.constructor" in URL input bar, it shows [object Window].
Morgan Cheng