Skip to content

Commit

Permalink
2024/07/13 時点の英語版に基づき更新
Browse files Browse the repository at this point in the history
  • Loading branch information
mfuji09 committed Sep 8, 2024
1 parent f14d1fd commit 34d0a0e
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
---
title: Symbol.asyncIterator
slug: Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator
l10n:
sourceCommit: 6e93ec8fc9e1f3bd83bf2f77e84e1a39637734f8
---

{{JSRef}}

**`Symbol.asyncIterator`** は、オブジェクトのデフォルトの AsyncIterator を指定します。このプロパティがオブジェクトに設定されている場合、それは非同期反復可能項目であり、[`for await...of`](/ja/docs/Web/JavaScript/Reference/Statements/for-await...of) ループで使用できます
**`Symbol.asyncIterator`** は静的データプロパティで、[ウェルノウンシンボル](/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol#ウェルノウンシンボル)である `Symbol.asyncIterator` を表します。[非同期反復可能プロトコル](/ja/docs/Web/JavaScript/Reference/Iteration_protocols#非同期イテレーターと非同期反復可能プロトコル)は、オブジェクトの非同期反復子を返すメソッドについてこのシンボルを検索します。オブジェクトが非同期反復可能であるためには、`[Symbol.asyncIterator]` キーを持つ必要があります

{{EmbedInteractiveExample("pages/js/symbol-asynciterator.html", "taller")}}

## 説明
##

`Symbol.asyncIterator` シンボルは、オブジェクトの `@@asyncIterator` メソッドにアクセスするための組み込みシンボルです。オブジェクトを非同期で反復可能にするには、`Symbol.asyncIterator` キーが必要です
ウェルノウンシンボル `Symbol.asyncIterator` です

{{js_property_attributes(0,0,0)}}
{{js_property_attributes(0, 0, 0)}}

##

### ユーザー定義の非同期反復可能項目

オブジェクトに `[Symbol.asyncIterator]` プロパティを設定することで、独自の非同期イテレータを定義することができます
オブジェクトに `[Symbol.asyncIterator]()` プロパティを設定することで、独自の非同期イテレーターを定義することができます

```js
const myAsyncIterable = {
Expand All @@ -33,29 +35,29 @@ const myAsyncIterable = {
(async () => {
for await (const x of myAsyncIterable) {
console.log(x);
// 期待される出力:
// "hello"
// "async"
// "iteration!"
}
})();
// 期待される出力:
// "hello"
// "async"
// "iteration!"
```

API を作成するとき、非同期反復可能項目はデータのストリームやリストのような、*反復可能*なものを表すために設計されたものであり、ほとんどの状況でコールバックやイベントを完全に置き換えるものではないことに注意してください。

### 組み込みの非同期反復処理
### 組み込みの非同期反復可能オブジェクト

現在のところ、デフォルトで `[Symbol.asyncIterator]` キーが設定されている組み込み JavaScript オブジェクトはありません。しかし、WHATWG Streams は非同期反復可能な最初の組み込みオブジェクトになるように設定されており、最近 `[Symbol.asyncIterator]` が仕様に組み込まれました
コア JavaScript 言語に非同期反復可能オブジェクトはありません。一部の Web API、例えば {{domxref("ReadableStream")}} は既定で `Symbol.asyncIterator` メソッドが設定されています

## 仕様
## 仕様書

{{Specifications}}

## ブラウザー実装状況
## ブラウザーの互換性

{{Compat}}

## 関連情報

- [反復処理プロトコル](/ja/docs/Web/JavaScript/Reference/Iteration_protocols)
- [for await... of](/ja/docs/Web/JavaScript/Reference/Statements/for-await...of)
- [for await...of](/ja/docs/Web/JavaScript/Reference/Statements/for-await...of)

0 comments on commit 34d0a0e

Please sign in to comment.