title: Global javascript object not defined error?
body: <p>I don't know if this is too localized or not but I don't have much code. The problem I am having is an object being declared in a global js file named <code>System.js</code> called <code>budgetModel</code> which holds data for the entire web app is showing as undefined. </p>
  
  <p>I created a class like object called <code>BudgetModel</code> in js within the <code>System.js</code> file and when a user logs in the website directs them to a page called <code>index.php</code> which onload executes two methods called <code>setupSystem()</code> and then <code>setup()</code>.</p>
  
  <p>Near the bottom of the html before the closing 'body' tag I placed two scripts, the <code>System.js</code> and a setup function to load the data that was passed from php to javascript using json as the variable <code>budgetcost</code> and another called <code>budgetexp</code>:</p>
  
  <pre><code>&lt;script src="util/js/System.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
  function setup(){
  
      budgetModel.setCost(budgetcost, budgetexp);
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Also in the <code>System.js</code> file I have this global function and variable:</p>
  
  <pre><code>var budgetModel;
  
  function setupSystem(){
  
      budgetModel = new BudgetModel();
  
  }
  </code></pre>
  
  <p>The <code>setupSystem</code> function is called before the <code>setup</code> function is called within the <code>index.php</code> file. The error I get is that it complains the <code>budgetModel</code> variable is not defined. How can this be fixed or is it even possible and if it is possible should my <code>System.js</code> script line be somewhere else?</p>
  
  <p>EDIT: 
  I fixed the problem. There was a very very small syntax error in the <code>System.js</code> file.
  I also noticed that window. syntax doesn't matter either way if the variable is declared global or not. Sorry for the bother everyone x_x</p>
  
  <p>EDIT2:</p>
  
  <p>Here is as much code as I can provide:</p>
  
  <p>index.php:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
      &lt;title&gt;Test Page&lt;/title&gt;
  
      &lt;link rel="stylesheet" href="util/css/globalStyles.css"&gt;
  
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  
  &lt;/head&gt;
  &lt;body onload="setup();"&gt;
  
  ...
  
  &lt;script src="util/js/System.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
      function setup(){
  
          if (typeof(budgetcost) !== 'undefined'){
  
              setupSystem();
  
              budgetModel.setModel(budgetcost, budgetexp);
  
              teamAssumpModel.setModel(teamagents);
  
          }
      }
  
      &lt;/script&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>System.js:</p>
  
  <pre><code>var budgetModel;
  var teamAssumpModel;
  
  
  function setupSystem(){
  
      window.budgetModel = new BudgetModel();
  
      window.teamAssumpModel = new TeamAssumpModel();
  
  }
  
  function TeamAssumpModel() {
  
      this.teamagents = [[]];
  
      this.setModel = function(teamagents){
          this.teamagents = teamagents;
      };
  
      this.getAgents = function(){
          return this.teamagents;
      };
  
  }
  
  function BudgetModel(){
  
      this.budgetcost = [[]];
      this.budgetexp = [[]];
  
      this.setModel = function(budgetcost, budgetexp){
          this.budgetcost = budgetcost;
          this.budgetexp = budgetexp;
      };
  
      this.getExp = function(){
          return this.budgetexp;
      };
  
      this.getCost = function(){
          return this.budgetcost;
      };
  
  }
  </code></pre>
  
  <p>So this is pretty much what what I have. budgetModel works in the index.php but when I include this same file into another php file it reads as undefined. What else is required to make it visible to other php files?</p>