Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:02:40+00:00 2026-06-13T18:02:40+00:00

I noticed that some of the legacy scripts that I’m working on for a

  • 0

I noticed that some of the legacy scripts that I’m working on for a project weren’t working anymore after my team upgraded to Dojo 1.8. Specifically, the global variable that they created wasn’t being created any more.

I dug around and found out that the Dojo 1.8 team is very much opposed to global variables. So opposed, in fact, that they make it physically impossible for the user to create a global variable in a required script using the following code at the end of their require:

req.eval =
        function(text, hint){
            return eval_(text + "\r\n////@ sourceURL=" + hint);
        };
var eval_ = new Function('return eval(arguments[0]);');

That’s wonderful and all, but the old code I’m working with can’t be changed, so I’ve been trying to figure out how to get around this and execute the eval in the local context instead.

Fortunately, dojo.eval is still there from older versions of Dojo, and that does what I want it to. So I just need to get access to req.eval and change the function to do return dojo.eval(...) or even just eval(...) in certain instances.

The problem is, I haven’t been able to figure out how to get access to req. Here’s what happens:

I include dojo.js in script tags at the top of my HTML file. It loads in its own script file.

dojo.require is accessible from my own files. It’s defined with define in the script file:

'dojo/_base/loader':function(){
define(["./kernel", "../has", "require", "module", "./json", "./lang", "./array"], function(dojo, has, require, thisModule, json, lang, array) {

I’m not sure if that’s important or not. Anyway, inside the scope of dojo.require, I can see something called injectModule, while in my own file I can’t. injectModule is a local variable so you can’t see it with this. It is defined in an anonymous function at the start of the file, i.e.

(function(){ ... injectModule = function(){} ... })();

Inside the injectModule function, there’s the following line:

req.getText(url, legacyMode!=sync, xhrCallback);

which goes to req.eval. So injectModule can see req.

I’m not sure what to do. None of my nefarious JavaScript tricks have helped me even begin to navigate this gridlock of scopes. A good start would be figuring out how to see injectModule from my outer script file that calls dojo.require. I wasn’t able to do it with ‘bind’, though, because it’s a local variable defined in an anonymous function. Is this even going to be possible?

To make things a little easier, here’s a summary:

File 1:

<script src="dojo.js"></script>
dojo.require(File 3);
console.log(globalVar);

File 2:

(function(){req.eval = unhelpful function})();
define(["require"], function(module){
    dojo.require = function(x){req.eval(x)}
});

File 3:

globalVar = ...;

I can modify files 1 and 3, but file 3 will always need a global variable. I can’t modify file 2. The goal is to change req.eval in file 2 to be a better function.

Declaring the global variable earlier doesn’t work because the scope change means file 3 still won’t be able to see it.

Reflection and string replacement doesn’t work because the scope is wrong and the JS is minified on the server-side.

Overwriting the methods from file 1 doesn’t work because I can’t see through the scope.

Using the JavaScript bind function has been fruitless as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:02:41+00:00Added an answer on June 13, 2026 at 6:02 pm

    Global scope can be accessed through the global window object, so window.foo = 'bar' is the same as creating a global variable foo. More details about this here: https://stackoverflow.com/a/4862268/168382

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am modifying some legacy project using SOAP web services. I noticed that some
I noticed that some arrays don't have a comma after the last item. I
I was looking through some legacy code we have and I noticed something that
I recently noticed that some (not all) of my javascript and jQuery scripts wouldn't
I was working with some legacy code today and noticed something strange. We have
I noticed that some jquery effects requires that scripts are loaded in proper order..
I am working with a .NET 3.5 application in C# that calls some legacy
I noticed that some enumerations have None as a enumeration member. For example what
I noticed that some stylesheets have something like this: body { font-size: 62.5%/1.2em; }
While reading cocoa tutorials i've noticed that some of the tutorials use AppDelegate and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.