Javascript Game Engine
<p>I'm trying to write a javascript game engine myself. I did something like this;
How do you think can make it more useful? Waiting for suggestions. thanks</p>

<p>How do I write less than this initial code, for example?</p>

<pre><code>    var jSgame = function(w,h,bgcolor){
    if(bgcolor == undefined){
      bgcolor = '#ccc';
    }
    this.bgcolor = bgcolor;
    if(w==undefined){
      w = 400;
    }
    if(h==undefined){
      h = 200;
    }
    this.w = w;
    this.h = h;
    this.start = function(){
      var c = document.createElement('canvas');
      if(c){
         c.style.backgroundColor = this.bgcolor;
         c.width = this.w;
         c.height = this.h;
         document.body.appendChild(c);
         this.ctx = c.getContext('2d');
      }
    }
  }

  jSgame.prototype.draw = function(x,y,bgcolor){
    a = new jSgame(x,y,bgcolor);
    a.start();
    this.ctx = a.ctx;
    this.rect=function(x,y,r,animate,clear,physics){
      ctx = this.ctx;
      var dx = 1;
      if(!animate||!clear){
        ctx.fillRect(x,y,r,r);
      }else if(animate&amp;&amp;clear){
        setInterval(function(){
          ctx.clearRect(0,0,a.w,a.h);
          ctx.fillRect(x,y,r,r);
          x += dx;
          if(physics){
            if(x+dx&gt;a.w-r){
              dx=-dx;
            }else if(x+dx&lt;0){
              dx=-dx;
            }
          }
        },1);
      }
    }
  }

 Game = new jSgame();
 Draw = new Game.draw(400,400,'#ccc');
 Draw.rect(10,10,10,true,true,true);​
</code></pre>
