Example 1 — super() in constructor
Must call before this.
JavaScript
class A { constructor(n) { this.n = n; } }
class B extends A {
constructor(n) { super(n); this.extra = true; }
}
console.log(new B(1).n);How It Works
- super(n) initializes the parent part.
