aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/operators/function_star_/index.html
blob: 7187f985bcf76f2db9b00962be68dda839e8d5e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
title: function* expression
slug: Web/JavaScript/Reference/Operators/function*
tags:
  - ECMAScript6
  - Function
  - Generator
  - JavaScript
translation_of: Web/JavaScript/Reference/Operators/function*
---
<div>{{jsSidebar("Operators")}}</div>

<p><strong><code>function*</code></strong> keyword 는 표현식 내에서 generator function 을 정의합니다.</p>

<div>{{EmbedInteractiveExample("pages/js/expressions-functionasteriskexpression.html")}}</div>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">function* [<em>name</em>]([<em>param1</em>[, <em>param2[</em>, ..., <em>paramN</em>]]]) {
   <em>statements</em>
}</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><code>name</code></dt>
 <dd>함수명. 생략하면, 익명 함수가 됩니다.  함수명은 함수내에만 한정됩니다.</dd>
 <dt><code>paramN</code></dt>
 <dd>함수에 전달되는 인수의 이름. 함수는 최대 255 개의 인수를 가질 수 있습니다.</dd>
 <dt><code>statements</code></dt>
 <dd>함수의 본체를 구성하는 구문들.</dd>
</dl>

<h2 id="Description">Description</h2>

<p><code>function*</code> expression 은 {{jsxref('Statements/function*', 'function* statement')}} 과 매우 유사하고 형식도 같습니다. <code>function*</code> expression 과 <code>function*</code> statement 의 주요한 차이점은 함수명으로,<em> </em><code>function*</code> expressions 에서는 익명 함수로 만들기 위해 함수명이 생략될 수 있습니다.보다 자세한 내용은 <a href="/ko/docs/Web/JavaScript/Reference/Functions">functions</a> 을 참조하십시오.</p>

<h2 id="Examples">Examples</h2>

<p>아래의 예제는 이름이 없는 generator function 을 정의하고 이를 x 에 할당합니다. function 은 인자로 들어온 값의 제곱을 생산(yield)합니다.</p>

<pre class="brush: js">var x = function*(y) {
   yield y * y;
};
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES2015', '#', 'function*')}}</td>
   <td>{{Spec2('ES2015')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#', 'function*')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat("javascript.operators.function_star")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Statements/function*", "function* statement")}}</li>
 <li>{{jsxref("GeneratorFunction")}} object</li>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">The Iterator protocol</a></li>
 <li>{{jsxref("Operators/yield", "yield")}}</li>
 <li>{{jsxref("Operators/yield*", "yield*")}}</li>
 <li>{{jsxref("Function")}} object</li>
 <li>{{jsxref("Statements/function", "function statement")}}</li>
 <li>{{jsxref("Operators/function", "function expression")}}</li>
 <li>{{jsxref("Functions_and_function_scope", "Functions and function scope")}}</li>
</ul>