Ticket #744 (closed defect: wontfix)
dj_eval not evaluating in the global window context in IE
| Reported by: | smorais@… | Owned by: | jburke |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0 |
| Component: | General | Version: | 0.3 |
| Severity: | normal | Keywords: | |
| Cc: | smorais@… |
Description (last modified by jburke) (diff)
I am using dojo.require to include a custom module outside of the dojo source tree. In this module, I declare a global (window scoped) variable like so:
var FOO = "bar";
dojo.require will then do an xmlhttprequest to fetch the context of my module and eval it using dj_eval. The problem is that in IE, window.eval will not evaluate the script in the context of the window, but rather in the context of the calling function, in this case dj_eval. So FOO will never be visible outside of my module. A workaround is to declare global variables in required modules like so:
FOO = "bar";
or like so:
window.FOO = "bar";
but this is a subtelty that will likely be lost on most module developers. A better solution will be to fix dj_eval to work right in IE:
function dj_eval(s){
if (dj_global.execScript){
return dj_global.execScript(s, "javascript");
} else if (dj_global.eval){
return dj_global.eval(s);
} else {
return eval(s);
}
}