title: How to load a custom script with require.js and make it export an object which I can access in my Backbone views?
body: <p>I am using require js for handling my Backbone application.</p>
  
  <p>I want to load a script called global (where I'll have several miscellaneous functions which i want to use in certain Backbone views).</p>
  
  <p>Here is the way I confid require js:</p>
  
  <pre><code>require.config({
  
          paths: {
              "jquery" : "libs/jquery",
              "underscore" : "libs/underscore",
              "backbone" : "libs/backbone",
              "text" : "libs/require/text",
              "global" : "libs/global",
              templates: '../templates'
          },
  
          shim: {
  
              backbone: {
                  deps: ["underscore", "jquery"],
                  exports: "Backbone"
              },
  
              underscore: {
                  exports: '_'
              },
  
              text : {
                  exports : 'text'
              }
          },
  
          global : {
              deps: ["jquery"],
              exports : 'Global'
          }
      });
  
      require([
  
          'jquery',
  
          'underscore',
  
          'backbone',
  
          'router',
  
          'global'
  
      ], function ($, _, Backbone, Router, Global) {
  
              console.log(Global);
  
              Backbone.View.prototype.close = function () {
  
                  this.$el.empty();
  
                  this.stopListening();
  
                  this.undelegateEvents();
              };
  
              var router = new Router();
  
              Backbone.history.start();
      });
  </code></pre>
  
  <p>As you can see, I am using the <strong>shim config</strong> method for loading the <strong>global.js</strong> file.</p>
  
  <p>I set it's <strong>dependencies</strong>, aka <strong>jQuery</strong>, and name it's export variable "<strong>Global</strong>" <code>function ($, _, Backbone, Router, Global) {</code></p>
  
  <p>How do I need to write the global file, in order to work, and basically, see something except undefiend when I do: <code>console.log(Global);</code></p>
  
  <p>I am thinking of something like this, but obviously isn't working:</p>
  
  <p>On <strong>global.js</strong>:</p>
  
  <pre><code>var Global = {
  
      resize : function () {
  
          console.log('this will be a resize function')
      }
  };
  
  return Global;
  </code></pre>
  
  <p>And on the config file, I should be able to do something like this: </p>
  
  <pre><code>require([
  
          'jquery',
  
          'underscore',
  
          'backbone',
  
          'router',
  
          'global'
  
      ], function ($, _, Backbone, Router, Global) {
  
          Global.resize;
  
          // Which would execut the resize function
  
  
      });
  </code></pre>
  
  <p>Any ideas?</p>