We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Super

The super keyword allows us to call methods on an object's parent. It's often used to call a parent's constructor method when the child object has its own.

class Titan {
  constructor(name) {
    this.name = name;
  }

  toString() {
    return `Titan - Name: ${this.name}`;
  }
}

class BeastTitan extends Titan {
  constructor(name, power) {
    // call the parent's constructor
    super(name);
    this.power = power;
  }

  toString() {
    // call the parent's `toString` method
    return `${super.toString()}, Power: ${this.power}`;
  }
}

const beast = new BeastTitan("Zeke", 9000);
console.log(beast.toString());
// Titan - Name: Zeke, Power: 9000

Assignment

They've decided that Sender subclasses should only be responsible for formatting the message. Both SMSSender and EmailSender should have a formatMessage method that calls the base Sender's formatMessage method, but appends either " [SMS]" or " [Email]" to the end of the message, depending on the subclass. For example:

To: [email protected], Message: You up? [SMS]