override methods
๐พ ็จๅผ๏ผreplit
// superclass
class A {
method() { log(`a.method() runs.`) } // โญ super.method()
}
// subclass
class B extends A {
// โญ replace `super.method()`
method() { log(`b.method() runs.`) } // "b.method() runs."
// โญ extend `super.method()`
method() {
log(`b.method() runs first, then:`) // "b.method() runs first, then"
super.method(); // "a.method() runs."
}
}
const bunny = new B();
bunny.method();
Last updated
Was this helpful?