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>
In IE8, the result is
1=[object Object]
2=undefined
3=undefined
4=undefined
The second script
seems to override the q
of window
.
If I change the code to window.q = {test: "test"};
of the first script
to q={test:"test"}
, the result will be the same as other browsers.
Is this a bug in IE?
Looks like a bug to me. In IE 10, the above yields
1=[object Object]
2=[object Object]
3=test
4=test
This is the same behaviour as Firefox.
EDIT: See also https://stackoverflow.com/a/2635726/1641070 and Why does IE nuke window.ABC variables?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With