classes

class Media {
  constructor(info) {
    this.name = info.name;
  }
  describe() {
    return this.name;
  }
}

class Song extends Media {
  constructor(info) {
    super(info);
    this.artist = info.artist;
  }
}

That is the shape A class is syntax over the prototype system , not a new object model

constructor

Runs on new Assign instance state there Argument objects keep the constructor readable when there are more than three fields

extends and super

extends sets up inheritance super(...) calls the parent constructor and must run before this is used in the child constructor

Private fields

class Account {
  #balance = 0;
  add(amount) { this.#balance += amount; }
  get balance() { return this.#balance; }
}

The # prefix is enforced by the language No naming convention needed

Static

static methods live on the class itself Use them for factory functions and utilities that do not need an instance

Next

Failure and time in 09 errors and async

Posted