diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/symbol/asynciterator | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/symbol/asynciterator')
| -rw-r--r-- | files/ja/web/javascript/reference/global_objects/symbol/asynciterator/index.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/symbol/asynciterator/index.html b/files/ja/web/javascript/reference/global_objects/symbol/asynciterator/index.html new file mode 100644 index 0000000000..386580dbd8 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/symbol/asynciterator/index.html @@ -0,0 +1,82 @@ +--- +title: Symbol.asyncIterator +slug: Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator +tags: + - ECMAScript 2018 + - JavaScript + - Property + - Reference + - Symbol + - asynchronous +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator +--- +<div>{{JSRef}}</div> + +<p><strong><code>Symbol.asyncIterator</code></strong> は、オブジェクトのデフォルトの AsyncIterator を指定します。このプロパティがオブジェクトに設定されている場合、それは非同期反復可能項目であり、<code><a href="/ja/docs/Web/JavaScript/Reference/Statements/for-await...of">for await...of</a></code> ループで使用できます。</p> + + + +<h2 id="Description" name="Description">説明</h2> + +<p><code>Symbol.asyncIterator</code> シンボルは、オブジェクトの <code>@@asyncIterator</code> メソッドにアクセスするための組み込みシンボルです。オブジェクトを非同期で反復可能にするには、<code>Symbol.asyncIterator</code> キーが必要です。</p> + +<p>{{js_property_attributes(0,0,0)}}</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="User-defined_Async_Iterables" name="User-defined_Async_Iterables">ユーザー定義の非同期反復可能項目</h3> + +<p>オブジェクトに <code>[Symbol.asyncIterator]</code> プロパティを設定することで、独自の非同期イテレータを定義することができます。</p> + +<pre class="brush: js notranslate">const myAsyncIterable = { + async* [Symbol.asyncIterator]() { + yield "hello"; + yield "async"; + yield "iteration!"; + } +}; + +(async () => { + for await (const x of myAsyncIterable) { + console.log(x); + // 期待される出力: + // "hello" + // "async" + // "iteration!" + } +})(); +</pre> + +<p>API を作成するとき、非同期反復可能項目はデータのストリームやリストのような、<em>反復可能</em>なものを表すために設計されたものであり、ほとんどの状況でコールバックやイベントを完全に置き換えるものではないことに注意してください。</p> + +<h3 id="Built-in_Async_Iterables" name="Built-in_Async_Iterables">組み込みの非同期反復処理</h3> + +<p>現在のところ、デフォルトで <code>[Symbol.asyncIterator]</code> キーが設定されている組み込み JavaScript オブジェクトはありません。しかし、WHATWG Streams は非同期反復可能な最初の組み込みオブジェクトになるように設定されており、最近 <code>[Symbol.asyncIterator]</code> が仕様に組み込まれました。</p> + +<h2 id="Specifications" name="Specifications">仕様</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ESDraft', '#sec-symbol.asynciterator', 'Symbol.asyncIterator')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザー実装状況</h2> + + + +<p>{{compat("javascript.builtins.Symbol.asyncIterator")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="/ja/docs/Web/JavaScript/Reference/Iteration_protocols">反復処理プロトコル </a></li> + <li><a href="/ja/docs/Web/JavaScript/Reference/Statements/for-await...of">for await... of</a></li> +</ul> |
