> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/class/inheritance/override-methods.md).

# 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](/web/js/val/class/inheritance/super.md) is used to refer to superclass's methods.
  {% endtab %}
  {% endtabs %}
