> 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/func/arrow/as-method.md).

# arrow function as method❗️

🚧 under construction

[JS](/web/js.md) ⟩ [objects](/web/js/val/obj.md) ⟩ [arrow function](/web/js/val/func/arrow.md) ⟩ as method

{% hint style="danger" %}
⭐️ ❗️<mark style="color:red;">**use with caution**</mark>❗️

<mark style="color:yellow;">**normally**</mark>, you <mark style="color:red;">**don't**</mark>**&#x20;**<mark style="color:yellow;">**use arrow functions as**</mark> [methods](https://developer.mozilla.org/en-US/docs/Glossary/Method), but if you have：

* an <mark style="color:yellow;">**object**</mark> <mark style="color:blue;">**A**</mark> that has a [method](/web/js/val/obj/method.md) <mark style="color:yellow;">**returning a new object**</mark> <mark style="color:blue;">**B**</mark>,&#x20;
* <mark style="color:yellow;">**object**</mark> <mark style="color:blue;">**B**</mark> has <mark style="color:yellow;">**its**</mark>**&#x20;**<mark style="color:red;">**own**</mark>**&#x20;**<mark style="color:yellow;">**methods**</mark>, you <mark style="color:red;">**don't want**</mark> [this](/web/js/concept/execution-context/this.md) in these methods to refer to <mark style="color:blue;">**B**</mark>, but <mark style="color:yellow;">**refer to**</mark>**&#x20;**<mark style="color:blue;">**A**</mark>**&#x20;**<mark style="color:yellow;">**instead**</mark>,&#x20;

then using <mark style="color:orange;">**arrow function as method**</mark> is an option.

👉 see example： [Sequence](/web/js/iteration/iterable/custom/sequence.md)
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}

* [Sequence](/web/js/iteration/iterable/custom/sequence.md) - an [iterable](/web/js/iteration/iterable.md) of numbers, \
  whose [iterator](/web/js/iteration/iterator.md) uses <mark style="color:yellow;">**arrow functions as methods**</mark>.
  {% endtab %}

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

* [arrow function as class field❗️](/web/js/val/func/arrow/arrow-function-as-class-field.md)
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] JS.info ⟩ [arrow functions revisited](https://javascript.info/arrow-functions)
  {% endtab %}

{% tab title="📘 手冊" %}

* [ ] [arrow functions used as methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#arrow_functions_used_as_methods) ⭐️
* [ ] [Method](https://developer.mozilla.org/en-US/docs/Glossary/Method)
  {% endtab %}

{% tab title="🗣 討論" %}

* [Methods in ES6 objects: using arrow functions](https://stackoverflow.com/questions/31095710/methods-in-es6-objects-using-arrow-functions)
  {% endtab %}
  {% endtabs %}
