Confused about variable visibility in Javascript
<p>I'm building a simple game engine in Javascript, and I've hit a wall named 'all functions are object classes'.</p>

<p>More specifically, I have the class</p>

<pre><code>function Game(){

}

Game.prototype = {
 update: function(){/* Blah */},
 draw:   function(){/* Foo */},

 start: function(fps){
        //Just a global var where I keep the FPS
        GS.fps = fps;
        var start = new Date().getTime();
        var time = 0;
        function timer(){
            time += (1000/fps);
            var diff = (new Date().getTime() - start) - time;
            if(true)
            {
                //Execute on itteration of the game loop
                this.update();  //It breaks here because this. is timer, not G.Game

                //Draw everything
                this.draw();

                window.setTimeout(timer,(1000/GS.fps - diff));

            }           
        };

}
</code></pre>

<p>I'm thinking of using global objects as containers for the update and draw functions, but this just feels wrong to me... Is there any other way? Is there a native JS way of accessing the parent class?</p>

<p>Thanks for your time!</p>
