JavaScript theorytheory 0/50 · 0%
Structure · easy

9. Classes

Constructors, methods, fields and extends.

Classes are syntax over prototypes. They support a constructor, instance fields, methods, `static` members, private `#fields` and `extends` with `super`.

class Wallet {
  #key;
  constructor(address) { this.address = address; }
  short() { return this.address.slice(0, 6); }
  static zero() { return new Wallet("0x0"); }
}

Methods live on the prototype and are shared; fields are per instance.

Check your understanding

  1. 1. Where do class methods live?

  2. 2. What does `#key` mean?

  3. 3. What must a subclass constructor call first?