1
的JavaScript代码在不同的浏览器不同的效果:为什么有些对象在IE中没有构造函数?下面
document.write(this.location.constructor);
document.write("<br/>");
document.write(this.constructor);
document.write("<br/>");
在Chrome中,页面有:
function Location() { [native code] }
function DOMWindow() { [native code] }
在Firefox中,页面有:
[object Location]
[object Window]
在IE8的页面有:
undefined
undefined
Chrome和Firefox的区别可能与toString()
的实现不同。我只是不明白为什么这两个对象的构造函数在IE中是undefined。如果他们的构造函数是未定义的,那么他们的原型呢?他们也是undefined?
我正在使用IE 8.0.6001.18372。 有趣的是,如果我加载一个本地html与“document.write(this.constructor)”,它是未定义的;如果我只是在URL输入栏中输入“javascript:this.constructor”,它会显示[object Window]。 – 2009-01-29 03:55:20