> 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/iteration/iterable/make-iterables.md).

# make iterables

[JS](/web/js.md)⟩ [iteration](/web/js/iteration.md) ⟩ [iterable](/web/js/iteration/iterable.md) ⟩ make iterables

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %}
we can make [class](/web/js/val/class.md)/[object](/web/js/val/obj.md) [iterable](/web/js/iteration/iterable.md) by letting them：

* make [iterator](/web/js/iteration/iterator.md) <mark style="color:yellow;">**object**</mark> directly ( 👉 see： [ClosedRange](/web/js/iteration/iterable/custom/closedrange.md))
* return new [iterator](/web/js/iteration/iterator.md) using [generator function](/web/js/iteration/generator/func.md) ( 👉 see：�[�例一](#fan-li) )
  {% endhint %}
  {% endtab %}

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

* [ ] 2ality ⟩ [iterable iterator](https://2ality.com/2021/08/iteration-helpers.html#iterators-that-are-also-iterable)
  {% endtab %}
  {% endtabs %}

## examples

{% tabs %}
{% tab title="💈例一" %}
{% hint style="success" %}
use [generator function](/web/js/iteration/generator/func.md) to return new [iterator](/web/js/iteration/iterator.md).
{% endhint %}

:floppy\_disk: replit：[make class iterable](https://replit.com/@pegasusroe/generate-iterables#index.js)

```javascript
// an iterable (that can make iterators)
class ValueContainer {

    // private properties
    #values;

    // init
    constructor(...values) {
        this.#values = values;
    }

    // ⭐ "make iterator" method
    // ⭐ use generator function to return new iterator
    *[Symbol.iterator]() {
        for (const value of this.#values) {
            yield value;
        }
    }

}

// main
let container = new ValueContainer(1,2,3);
[...container];        // [ 1, 2, 3 ]
```

{% endtab %}

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

* [private member](/web/js/val/class/member/private.md)
  {% endtab %}
  {% endtabs %}
