You can use window.eval() to run eval() from the global scope. This will assign var as the window variable, which is a global variable: the variable bound to window .
... But you really shouldn't do that. eval() is the default sandbox.
This is not the case if you really donβt know what you are doing and trust everything you get through XMLHttpRequest . This is one of these things from chicken / eggs: if you trust enough code to execute it, it must be programmed well enough to start with the global variable prefix using window. ; this way you do not need to use window.eval() .
Also, if you're just not trying to avoid asynchronous headaches by using the more manageable XMLHttpRequest (there for the first time for everything ...), you really just need to create a script tag, assign it a source, and add it as a child to the head tag or body. Dynamically adding script tags is faster than using XHR, especially for large scripts.
source share