title: Uncaught TypeError: Cannot read property 'getContext' of undefined
body: <p>I get this error "Uncaught TypeError: Cannot read property 'getContext' of undefined " while running script. It seems that variable "canvas" is undefined but I can't figure out why.</p>
  
  <pre><code>var world = {
      canvas: document.getElementById("myCanvas"),
      context: this.canvas.getContext("2d"),
      centerX: this.canvas.width / 2,
      centerY: this.canvas.height / 2,
      drawShape: function (shape) {
          if (typeof shape.draw() === "function")
              shape.draw();
      }
  };
  </code></pre>