Step 6

Let's implement the Sprite class:

import Block from "./Block.js";

class Sprite extends Block {
  constructor(x, y, width, height, color) {
    super(x, y, width, height, color);
  }

  move(dx, dy) {
    this.x += dx;
    this.y += dy;
  }
}

export default Sprite;

Notice the use of extends keyword to use Inheritance. Also take note of the use of the keyword super to invoke the constructor of the parent class.

The constructor of Sprite is not needed; if we eliminate it, the constructor of the parent class is inherited. This is different from e.g. Java where you must explicitly declare (non-default) constructors.