<分区>
Possible Duplicate:
Why does IE nuke window.ABC variables?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<script>
if(typeof q === "undefined"){
window.q = {test: "test"};
}
alert("1="+q)
</script>
<script>
alert("2="+q)
if(typeof q === "undefined"){
var q = {};
}
alert("3="+q.test)
</script>
<script>
alert("4="+q.test)
</script>
</body>
在IE8中,结果是
1=[object Object]
2=undefined
3=undefined
4=undefined
第二个脚本
似乎覆盖了window
的q
。
如果我将第一个 script
的代码更改为 window.q = {test: "test"};
为 q={test:"test "
,结果会和其他浏览器一样。
这是 IE 中的错误吗?