title: Require.js - set return value for callback function
body: <p>It seems like <code>require</code> calls are executed asynchronously, allowing program flow to continue around them. This is problematic when I'm trying to use a value set within a <code>require</code> call as a return value. For instance:</p>
  
  <p>main.js:</p>
  
  <pre><code>$(document).ready(function() {
      requirejs.config({
          baseUrl: 'js'
      });
  
      requirejs(['other1'], function(other1) {
          console.log(other1.test()); //logs out 'firstValue', where I would expect 'secondValue'
      }
  });
  </code></pre>
  
  <p>other1.js</p>
  
  <pre><code>function test() {
      var returnValue = 'firstValue'; //this is what is actually returned, despite the reassignment below...
      requirejs(['other2'], function(other2) {
          other2.doSomething();
          returnValue = 'secondValue'; //this is what I really want returned
      })
      return returnValue;
  }
  
  if(typeof module != 'undefined') {
      module.exports.test = test;
  }
  
  if(typeof define != 'undefined') {
      define({
          'test':test
      });
  }
  </code></pre>
  
  <p>How can I set a return value for a function from inside a <code>require</code> block?</p>