# override methods

{% tabs %}
{% tab title="💾 程式" %}
💾 程式：[replit](https://replit.com/@pegasusroe/JS-override-methods#index.js)

```javascript
// 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();   
```
{% endtab %}

{% tab title="📗 參考" %}
* [x] JS.info ⟩ [overriding constructor](https://javascript.info/class-inheritance#overriding-constructor)
{% endtab %}

{% tab title="👥 相關" %}
* [super](super "mention") is used to refer to superclass's methods.
{% endtab %}
{% endtabs %}
