From 3e59b53e2a5eca5222720cf50d62d24de6e5cfce Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sat, 19 Feb 2022 21:22:37 +0900 Subject: 2022/02/18 時点の英語版に同期 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reference/operators/yield_star_/index.md | 111 +++++++++------------ 1 file changed, 49 insertions(+), 62 deletions(-) (limited to 'files/ja') diff --git a/files/ja/web/javascript/reference/operators/yield_star_/index.md b/files/ja/web/javascript/reference/operators/yield_star_/index.md index 5dae616341..9cca07268b 100644 --- a/files/ja/web/javascript/reference/operators/yield_star_/index.md +++ b/files/ja/web/javascript/reference/operators/yield_star_/index.md @@ -3,47 +3,45 @@ title: yield* slug: Web/JavaScript/Reference/Operators/yield* tags: - ECMAScript 2015 - - Generators - - Iterable - - Iterator - - JavaScript - - Operator - - Reference - - yield* - ジェネレーター + - 反復可能 + - 反復子 + - JavaScript + - 言語機能 - 演算子 + - リファレンス +browser-compat: javascript.operators.yield_star translation_of: Web/JavaScript/Reference/Operators/yield* --- -
{{jsSidebar("Operators")}}
- -

yield*は別の {{jsxref("Statements/function*", "ジェネレーター", "", 1)}} や反復可能なオブジェクトに委任するために使用されます。

+{{jsSidebar("Operators")}} -
{{EmbedInteractiveExample("pages/js/expressions-yieldasterisk.html")}}
+**`yield*` 式**は別の{{jsxref("Statements/function*", "ジェネレーター", "", 1)}}や反復可能なオブジェクトに委任するために使用されます。 - +{{EmbedInteractiveExample("pages/js/expressions-yieldasterisk.html")}} -

構文

+## 構文 -
 yield* expression;
+```js +yield* expression +``` -
-
expression
-
反復可能なオブジェクトを返す式。
-
+- `expression` + - : 反復可能なオブジェクトを返す式。 -

解説

+## 解説 -

yield* 式はオペランドを反復し、それによって返されたそれぞれの値をもたらします。

+`yield*` 式はオペランドを反復し、それによって返されたそれぞれの値をもたらします。 -

yield* 式自体の値は、イテレーターが閉じたとき (つまり donetrue のとき) に返される値です。

+`yield*` 式自体の値は、イテレーターが閉じたとき(つまり `done` が `true` のとき)に返される値です。 -

+## 例 -

別のジェネレータに委任する

+### 別のジェネレータに委任する -

次のコードでは、 g1() によってもたらされる値は、 g2() で得られているものと同じように next() の呼び出しから返されます。

+次のコードでは、 `g1()` によってもたらされる値は、 `g2()` で得られているものと同じように `next()` の呼び出しから返されます。 -
function* g1() {
+```js
+function* g1() {
   yield 2;
   yield 3;
   yield 4;
@@ -63,13 +61,14 @@ console.log(iterator.next()); // {value: 3, done: false}
 console.log(iterator.next()); // {value: 4, done: false}
 console.log(iterator.next()); // {value: 5, done: false}
 console.log(iterator.next()); // {value: undefined, done: true}
-
+``` -

他の反復可能なオブジェクト

+### 他の反復可能なオブジェクト -

ジェネレータオブジェクトのほかに、 yield* は他の種類の反復 (例えば、配列、文字列、 {{jsxref("Functions/arguments", "arguments")}} オブジェクト) を yield することができます。

+ジェネレータオブジェクトのほかに、 `yield*` は他の種類の反復 (例えば、配列、文字列、 {{jsxref("Functions/arguments", "arguments")}} オブジェクト) を `yield` することができます。 -
function* g3() {
+```js
+function* g3() {
   yield* [1, 2];
   yield* '34';
   yield* Array.from(arguments);
@@ -84,13 +83,14 @@ console.log(iterator.next()); // {value: "4", done: false}
 console.log(iterator.next()); // {value: 5, done: false}
 console.log(iterator.next()); // {value: 6, done: false}
 console.log(iterator.next()); // {value: undefined, done: true}
-
+``` -

yield* 式自体の値

+### `yield*` 式自体の値 -

yield* は式であり、文ではありません。そのため、値に評価されます。

+`yield*` は式であり、文ではありません。そのため、値に評価されます。 -
function* g4() {
+```js
+function* g4() {
   yield* [1, 2, 3];
   return 'foo';
 }
@@ -107,32 +107,19 @@ console.log(iterator.next()); // {value: 1, done: false}
 console.log(iterator.next()); // {value: 2, done: false}
 console.log(iterator.next()); // {value: 3, done: false} done is false because g5 generator isn't finished, only g4
 console.log(iterator.next()); // {value: 'foo', done: true}
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-generator-function-definitions-runtime-semantics-evaluation', 'Yield')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.operators.yield_star")}}

- -

関連情報

- - +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- [Iterator プロトコル](/ja/docs/Web/JavaScript/Guide/The_Iterator_protocol) +- {{jsxref("Statements/function*", "function*")}} +- {{jsxref("Operators/function*", "function* expression")}} +- {{jsxref("Operators/yield", "yield")}} -- cgit v1.2.3-54-g00ecf