> 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/obj/method/polymorphism.md).

# polymorphism

{% hint style="success" %} <mark style="color:purple;">**polymorphism**</mark> means "<mark style="color:yellow;">**same**</mark> [method](/web/js/val/obj/method.md) <mark style="color:yellow;">**name**</mark>, <mark style="color:red;">**different**</mark>**&#x20;**<mark style="color:yellow;">**callers**</mark>".

```javascript
dog.speak()    // caller: dog
cat.speak()    // caller: cat
```

{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %} <mark style="color:orange;">**function overloading**</mark>**&#x20;vs.&#x20;**<mark style="color:purple;">**polymorphism**</mark>

* [function overloading](/web/js/val/func/overload.md)：<mark style="color:yellow;">**same**</mark> [function name](/web/js/val/func/name.md), <mark style="color:red;">**different**</mark> [parameter](/web/js/val/func/param.md)(s).
* [polymorphism](/web/js/val/obj/method/polymorphism.md)：<mark style="color:yellow;">**same**</mark> [method](/web/js/val/obj/method.md) <mark style="color:yellow;">**name**</mark>, <mark style="color:red;">**different**</mark>**&#x20;**<mark style="color:yellow;">**callers**</mark><mark style="color:red;">**.**</mark>
  {% endhint %}
  {% endtab %}

{% tab title="👥 相關" %}

* don't confuse with [function overloading](/web/js/val/func/overload.md)(<mark style="color:yellow;">**same function name**</mark>, <mark style="color:red;">**different parameters**</mark>).
  {% endtab %}
  {% endtabs %}
