Does IE create new scope for each script tag?
cross-browser, javascript
Solution
HTML `<script>` tags Javascript are executed in the scope of the `window`. Thus, separated script tags are executed on the same scope.
Specifically with IE7, try not re-defining the variable on the second time:
Instead of
var mylib = mylib || {};
use
mylib = window.mylib || {};
IE7 probably overwrites the definition of `mylib` when `var mylib` is encountered.
Problem
Why is the following html file showing title as default in IE? The other browsers show title as mytitle. ``` <script> window.mylib = window.mylib || {}; mylib.title = 'mytitle'; </script> <script> var mylib = mylib || {}; document.title = mylib.title || 'default'; </script> ``` Does IE create a separate scope for each of the script tags? And is that just a bug or why does the behavior differ? (tested in IE8 and latest chrome/ff/opera)