title: canvas fillRect() not working
body: <p>I am new to canvas and java script and have no idea why it is not working. The 2 alerts are firing but color of the canvas is not changing every 1 sec as I intended it to do.</p>
  
  <pre><code>    var canvas = function(width, height, color){
      this.width = width;
      this.height = height;
      this.color = color;
      var instance = document.createElement('canvas');
      document.body.appendChild(instance);
      instance.width = this.width;
      instance.height = this.height;
      var ctx = instance.getContext('2d');
      ctx.fillStyle = color;
      ctx.fillRect(0, 0, this.width, this.height);
  
      this.changeBackground = function(color){
          ctx.fillStyle = color;
          ctx.fillRect(0, 0, this.width, this.height);
      }
  
      this.clear = function(){
          ctx.clearRect(0, 0, this.width, this.height);
      }
      var flag = true;
      setInterval(function(){
          if(flag) {
              ctx.fillStyle = 'blue';
              ctx.fillRect(0, 0, this.width, this.height);
              alert('blue');
          }
          else {
              ctx.fillStyle = 'green';
              ctx.fillRect(0, 0, this.width, this.height);
              alert('green');
          }
          flag = !flag;
      },1000);
      }
  
      var gameCanvas = new canvas(800, 600, 'green');
  </code></pre>