M
mikewse
I came across this strange little bug in IE 6 and 7, described below.
Does anyone know if it has been reported before and where it may be
possible to find more information about it?
Description
-----------
Two script blocks in a page. The first block assigns a global variable
though "window.myObj" syntax. The second block queries it without
window prefix. It works as expected as long as the last line is not
uncommented. Uncommenting the referred if-statement causes the "myObj"
definition to disappear from the second text block and alert(myObj)
will show "undefined" although executed before the uncommented
statement.
<script type='text/javascript'>
window.myObj = {};
alert( myObj );
</script>
<script type='text/javascript'>
alert( myObj );
// the following line causes myObj == undefined !
// if (myObj == null) var myObj = {};
</script>
Does anyone know if it has been reported before and where it may be
possible to find more information about it?
Description
-----------
Two script blocks in a page. The first block assigns a global variable
though "window.myObj" syntax. The second block queries it without
window prefix. It works as expected as long as the last line is not
uncommented. Uncommenting the referred if-statement causes the "myObj"
definition to disappear from the second text block and alert(myObj)
will show "undefined" although executed before the uncommented
statement.
<script type='text/javascript'>
window.myObj = {};
alert( myObj );
</script>
<script type='text/javascript'>
alert( myObj );
// the following line causes myObj == undefined !
// if (myObj == null) var myObj = {};
</script>