title: Calling Superclass Method From Subclass - JavaScript
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13167386/set-attribute-with-javascript-super-method">set attribute with javascript super method</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to create a simple game in HTML5 for fun. I have an Entity class that is supposed to be the superclass of the Player class.</p>
  
  <pre><code>function Entity(x, y) {
  
      this.x = x;
      this.y = y;
  
      this.tick = function() {
          //Do generic stuff
      }
  }
  
  function Player(x, y) {
  
      this.parent.constructor.call(this, x, y);
  
      this.tick = function() {
          //Do player-specific stuff
          this.parent.tick.call(this);
      }
  }
  
  Player.prototype = new Entity();
  Player.prototype.constructor = Player;
  Player.prototype.parent = Entity.prototype;
  </code></pre>
  
  <p>The problem is at this line:</p>
  
  <pre><code>this.parent.tick.call(this);
  </code></pre>
  
  <p>I get an error displayed in the JavaScript console of chrome: "Uncaught TypeError: Cannot call method 'call' of undefined".</p>
  
  <p>I don't get it and I've spent a long time trying to find posts of a similar issue. My call to the superclass' constructor works fine but the call to the superclass' tick method does not work.</p>
  
  <p>I'm very new to making games so I have no idea if this a good setup (calling superclass tick from subclass tick). If there is a better, more typical way that people use, please tell.</p>
  
  <p>Thanks.</p>