Opened 14 years ago

Last modified 11 years ago

#744 closed defect

dj_eval not evaluating in the global window context in IE — at Initial Version

Reported by: [email protected] Owned by: anonymous
Priority: high Milestone: 1.0
Component: General Version: 0.3
Keywords: Cc: [email protected]
Blocked By: Blocking:

Description

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);

}

}

Change History (0)

Note: See TracTickets for help on using tickets.