If you can put all your code in a single file (for example, with a shell script that calls "cat"), this might work:
window.realWindow = window; (function(){ var window = {document: {something: "hi!"}}; var document = window.document; /////////////////////////////////// // your code goes here, for example: function test (foo) { alert (document.something + " " + foo); realWindow.document.title = foo; } test("from inside"); // to make the function "test" reachable from the outside realWindow.global_test = test; /////////////////////////////////// })(); global_test("from outside");
Now your global variables will not be true global, but the "window" can be accessed from anywhere inside and will be your own version. Please note that this will violate some designs and make access to things βfrom outsideβ more difficult .... but in many cases it may just work without changing your code.
Edit: add an example of how to access something from an external closing function block
source share