title: Why must I access a global variable through window?
body: <p>I have some JS in a file, and some JS on a page.</p>
  
  <p>If I try to access my function via NucleusPreview, it can't be found<br>
  If I access it via window.NucleusPreview, it is found</p>
  
  <p>Why is that?  Am I doing something wrong, or do I need to be explicit when accessing objects in window scope when in another function?</p>
  
  <p>Update: I <em>was</em> creating NucleusPreview inside the onReady, but moved it so I think the window scope was a red herring.  The problem is that when calling it in onReady, gave it time to load the file, but when I moved it out I started calling it too early.</p>
  
  <p>The JS in the the file is basically:</p>
  
  <pre><code>var NucleusPreview;
  
  (function ($) {
      NucleusPreview = function NucleusPreview(source) {
          //ctor stuff
      };
  
      NucleusPreview.prototype.AdjustCaption = function AddCaption() {
          //caption stuff
      };
  })(jQuery);
  </code></pre>
  
  <p>My JS on the page:</p>
  
  <pre><code>$('.nucleus-preview').each(function eachNucleusPreview(index, element) {
      var jElement = $(element),
          vidId = jElement.data('video-id'),
          np = new NucleusPreview($(element)); //Uncaught RefError: NucleusPreview is not defined
  
      _wq.push({
          id: vidId,
          onReady: function (video) {
              np.AdjustCaption();
          }
      });
  });
  </code></pre>