Suppose I have the following script, called include_strict.js
. After it executes I should have window.global1
defined:
"use strict";
var globalVar = {};
alert(typeof window.globalVar);
But if I include it from a block of javascript with
$.getScript("include_strict.js");
The alert says undefined
. Why? What is going on here?
FYI, that's not what happens if I include the file using a script tag:
<script type="text/javascript" src="include_strict.js"></script>
Here, I see the expected alert, object
. And if I remove "use strict";
, then both jQuery.getScript()
and <script>;
have the same effect of displaying object
.
I've created an example (https://docs.google.com/file/d/0B-XXu97sL1Ckb0x0OHptTmVMY00/edit) to demonstrate this.