title: RequireJS: How do I pass variables from one file to another?
body: <p>I'm using require with backbone + backbone-forms. I'm currently using RequireJS to seperate code into multiple files. I have models stored in separate files and want to keep form validators separately. </p>
  
  <p>However, I am unable to access variables defined in one files, in another file that depends on this one. What I get is <code>Uncaught ReferenceError: isEmptyName is not defined</code>. <code>isEmptyName</code> is defined in validators and used in model. Any feedback about RequireJS config is also appreciated.</p>
  
  <p>My config:</p>
  
  <pre><code>requirejs.config({
  
  //By default load any module IDs from js/lib
  
  baseUrl: 'js',
  
  paths: {
       jquery: 'lib/jquery',
          app: 'lib/app', 
       wizard: 'lib/jquery.bootstrap.wizard.min',
    bootstrap: 'lib/bootstrap.min',
   underscore: 'lib/underscore-min',
     backbone: 'lib/backbone-min',
  backboneForms: 'lib/backbone-forms.min',
  langSwitcher: 'lib/lang',
       cookie: 'lib/cookie',
   datepicker: 'lib/bootstrap-datepicker',
         mask: 'lib/jquery.maskedinput.min',
   validators: 'modules/validators',  
  
    // models
  
  personalData: 'models/personal-data',
  addressData: 'models/address-data',
     workData: 'models/work-data',
  productsData: 'models/products-data',
  statmentData: 'models/statment-data',    
  
       model: 'models/form',
  collection: 'collections/form',
        view: 'views/form',
  
       setup: 'setup',
        send: 'send',
  
  },
      shim: {
      'underscore': {
          deps: ['jquery'],
          exports: '_'
      },  
      'backbone': {
          deps: ['underscore', 'jquery'],
          exports: 'backbone'
      },
  
      // all model needs to go within one collection
  
      'bootstrap' : ['jquery'],
      'wizard': ['jquery'],
      'backboneForms': ['backbone'],
      'validators': ['backbone','mask'],
      'personalData' : ['backbone','backboneForms','validators'],
      'addressData': ['backbone','backboneForms'],
      'workData': ['backbone','backboneForms'],
      'statmentData': ['backbone','backboneForms'],
  
      //'collection': ['backbone','backboneForms','personalData'],
      //'view': ['backbone','backboneForms','personalData']
   } 
  });
  </code></pre>
  
  <p>Beginning of validators.js</p>
  
  <pre><code>require(['backbone','backboneForms'], function(){
  
  
  var lettersOnly = /^[A-Za-zęóąśłżźćńĘÓĄŚŁŻŹĆŃ]+$/;
  var lettersOnlyDash = /^[A-Za-zęóąśłżźćńĘÓĄŚŁŻŹĆŃ\-]+$/;
  var err = {};
  var errCh = {};
  var errFormat = {};
  
  var isEmptyName = function(value){
  err = { message: 'Wpisz imię.'};
  if (value.length === 0) return err;
  };
  </code></pre>
  
  <p>Beginning of model.js that needs the validators in validators.js</p>
  
  <pre><code>require(['backbone','backboneForms','mask','validators'], function(backbone,backboneForms,mask,validators){
  
  var PersonalData = Backbone.Model.extend({
  
  schema: {
      first_name:{ 
          title: 'Imię',            
          validators: [isEmptyName, isLetter, minCharCount] //Accessing validators.js members here...
      }, ...
  </code></pre>