title: Javascript constructor seems to be losing data
body: <p>So, I've got a constructor for a splash screen. I'm using canvas graphics (ctx below is a reference to 2d context of the canvas element), but it seems when I try and get a local copy of the context that I lose it. Does someone have an idea why it becomes undefined where it does?(see below)</p>
  
  <pre><code>function SplashScreen(_ctx)
  {
      this.loadScene = function()
      {
          this.img = new Image();
          this.img.onload = this.render;
          this.img.src = 'art/SplashScreen.png';
      };
  
      this.unloadScene = function()
      {
          delete this.img;
          this.img = null;
          CollectGarbage();
      };
  
      this.render = function()
      {
          alert(this.ctx);//&lt;--------------undefined
          alert(this.img);//&lt;--------------undefined
          this.ctx.drawImage(this.img,0,0);
      };
  
      alert(_ctx);    //&lt;--------------properly defined
      this.ctx = _ctx;
      alert(this.ctx);//&lt;--------------properly defined
      return this;
  }
  </code></pre>
  
  <p>Here is where I'm calling SplashScreen(note: the below is from main.js, and the above is in splashscreen.js):</p>
  
  <pre><code>var ctx;
  
  var scene_Splash;
  var currentScene;
  
  function main()
  {
    ctx = document.getElementById('canvas').getContext('2d');
    alert(ctx); //&lt;-------fine and defined
    scene_Splash = new SplashScreen(ctx);
    changeScene(scene_Splash, null, null);
  }
  
  function changeScene(_newScene, _transition, _time)
  {
    currentScene = _newScene;
  
    currentScene.loadScene();
  }
  </code></pre>
  
  <p>Expanding on this even further, here is the part of the index.html file that is referencing these scripts:</p>
  
  <pre><code>&lt;html&gt;
   &lt;head&gt;
      &lt;script language="JavaScript" type="text/javascript" src="splashscreen.js"&gt;&lt;/script&gt;
      &lt;script language="JavaScript" type="text/javascript" src="main.js"&gt;&lt;/script&gt;
   &lt;/head&gt;
   &lt;body onload="main()"&gt;
     &lt;canvas id="canvas" width="640" height="960"&gt;&lt;/canvas&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>