From 93b4dd6b26fbce6f5e0c88f102da5b38e0289200 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 30 Aug 2021 00:24:16 +0900 Subject: Web/JavaScript/Reference/Operators/function* を更新 (#2180) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown化し、2021/08/21時点の英語版に同期 --- .../reference/operators/function_star_/index.html | 86 ---------------------- .../reference/operators/function_star_/index.md | 73 ++++++++++++++++++ 2 files changed, 73 insertions(+), 86 deletions(-) delete mode 100644 files/ja/web/javascript/reference/operators/function_star_/index.html create mode 100644 files/ja/web/javascript/reference/operators/function_star_/index.md diff --git a/files/ja/web/javascript/reference/operators/function_star_/index.html b/files/ja/web/javascript/reference/operators/function_star_/index.html deleted file mode 100644 index 3518adf63b..0000000000 --- a/files/ja/web/javascript/reference/operators/function_star_/index.html +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: function* 式 -slug: Web/JavaScript/Reference/Operators/function* -tags: - - ECMAScript6 - - Function - - Iterator - - JavaScript - - Operator - - Primary Expression - - 演算子 - - 関数 -translation_of: Web/JavaScript/Reference/Operators/function* ---- -
{{jsSidebar("Operators")}}
- -

function* キーワードは、式の中でジェネレーター関数を定義するために使用することができます。

- -
{{EmbedInteractiveExample("pages/js/expressions-functionasteriskexpression.html", "taller")}}
- - - -

構文

- -
function* [name]([param1[, param2[, ..., paramN]]]) {
-   statements
-}
- -

引数

- -
-
name {{optional_inline}}
-
関数名。省略可。省略した場合、関数は無名関数として認識されます。名前は関数本体のみにローカルです。
-
paramN  {{optional_inline}}
-
関数に渡される引数の名前。関数は最大 255 の引数を持ち得ます。
-
statements
-
関数の本体を構成するステートメント。
-
- -

解説

- -

function* 式は {{jsxref('Statements/function*', 'function* 文', "", 1)}}ととてもよく似ており、構文もほとんど同じです。function* 式と function* 文の主な違いは、function* 式で無名ジェネレーター関数を生成するには関数名が省略できる点です。詳細は {{jsxref("Functions", "functions")}} をご覧ください。

- -

- -

function* を使用する

- -

次の例では、無名ジェネレーター関数を定義し、x に割り当てます。関数は引数の二乗をもたらします:

- -
let x = function*(y) {
-   yield y * y;
-};
-
- -

仕様

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-generator-function-definitions', 'function*')}}
- -

ブラウザーの互換性

- -

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

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/operators/function_star_/index.md b/files/ja/web/javascript/reference/operators/function_star_/index.md new file mode 100644 index 0000000000..19a8d1404b --- /dev/null +++ b/files/ja/web/javascript/reference/operators/function_star_/index.md @@ -0,0 +1,73 @@ +--- +title: function* 式 +slug: Web/JavaScript/Reference/Operators/function* +tags: + - ECMAScript 2015 + - Function + - Iterator + - JavaScript + - Language feature + - Operator + - Primary Expression +browser-compat: javascript.operators.generator_function +translation_of: Web/JavaScript/Reference/Operators/function* +--- +{{jsSidebar("Operators")}} + +**`function*`** キーワードは、式の中でジェネレーター関数を定義するために使用することができます。 + +{{EmbedInteractiveExample("pages/js/expressions-functionasteriskexpression.html", + "taller")}} + +## 構文 + +```js +function* [name]([param1[, param2[, ..., paramN]]]) { + statements +} +``` + +### 引数 + +- `name` {{optional_inline}} + - : 関数名。省略可。省略した場合、関数は*無名関数*として認識されます。名前は関数本体のみにローカルです。 +- `paramN` {{optional_inline}} + - : 関数に渡される引数の名前。関数は最大 255 個の引数を持つことができます。 +- `statements` + - : 関数の本体を構成する文。 + +## 解説 + +`function*` 式は {{jsxref('Statements/function*', 'function* 文', "", 1)}}ととてもよく似ており、構文もほとんど同じです。`function*` 式と `function*` 文の主な違いは、`function*` 式で*無名*ジェネレーター関数を生成する場合は*関数名*が省略できる点です。詳細は {{jsxref("Functions", "functions")}} をご覧ください。 + +## 例 + +### function* の使用 + +次の例では、無名ジェネレーター関数を定義し、`x` に代入します。関数は引数の二乗を生成します。 + +```js +let x = function*(y) { + yield y * y; +}; +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Statements/function*", "function*")}} 文 +- {{jsxref("GeneratorFunction")}} オブジェクト +- [反復プロトコル](/ja/docs/Web/JavaScript/Reference/Iteration_protocols) +- {{jsxref("Operators/yield", "yield")}} +- {{jsxref("Operators/yield*", "yield*")}} +- {{jsxref("Function")}} オブジェクト +- {{jsxref("Statements/function", "function")}} 文 +- {{jsxref("Operators/function", "function")}} 式 +- {{jsxref("Functions_and_function_scope", "関数と関数スコープ", "", 1)}} -- cgit v1.2.3-54-g00ecf