title: Why does commenting out the alert() line of this code make it fail?
body: <p>I have a very odd problem with javascript. If you take the following code and run it, it will run fine without any error, but if you comment the first <code>alert</code>, it will throw an error at line 5 (<code>var _board = Bomber.BoardFactory.getBoard();</code>) saying BoardFactory doesn't exist (remember that with the first alert everything was running without error).  I have been able to reproduce this exact behavior with Firefox and Chrome.</p>
  
  <pre><code>Bomber = {};
  
  Bomber.Game = function () {
      var self = {};
      var _board = Bomber.BoardFactory.getBoard();
  
      self.init = function () {};
      self.start = function () {};
  
      return self;
  }
  
  alert("2");
  
  (function () {
      var instance;
  
      Bomber.BoardFactory = {};
      Bomber.BoardFactory.getBoard = function () {
          if (!instance)
              instance = new Bomber.Board();
          return instance;
      };
  })();
  
  alert("3");
  
  Bomber.Board = function () {
      var self = {};
      return self;
  }
  
  $(document).ready(function () {
      var game = Bomber.Game();
      game.init();
      game.start();
  });
  </code></pre>
  
  <p>My question, is what can possibly cause this odd behavior ? How on earth is it possible that an alert call makes it recognize the <code>Bomber.BoardFactory</code> ?</p>