From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../global_objects/generatorfunction/index.html | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 files/ko/web/javascript/reference/global_objects/generatorfunction/index.html (limited to 'files/ko/web/javascript/reference/global_objects/generatorfunction/index.html') diff --git a/files/ko/web/javascript/reference/global_objects/generatorfunction/index.html b/files/ko/web/javascript/reference/global_objects/generatorfunction/index.html new file mode 100644 index 0000000000..73ee12769d --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/generatorfunction/index.html @@ -0,0 +1,112 @@ +--- +title: GeneratorFunction +slug: Web/JavaScript/Reference/Global_Objects/GeneratorFunction +tags: + - Constructor + - ECMAScript 2015 + - Iterator + - JavaScript + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/GeneratorFunction +--- +
{{JSRef}}
+ +

GeneratorFunction 생성자는 새로운 {{jsxref("Statements/function*", "generator function")}} 객체를 생성한다. JavaScript 에서 모든 generator function 은 실제로 GeneratorFunction object 이다.

+ +

주의할 점은, GeneratorFunction 이 전역 객체(global object)가 아니란 점이다. GeneratorFunction은 다음의 코드를 실행해서 얻을 수 있다.

+ +
Object.getPrototypeOf(function*(){}).constructor
+
+ +

Syntax

+ +
new GeneratorFunction ([arg1[, arg2[, ...argN]],] functionBody)
+ +

Parameters

+ +
+
arg1, arg2, ... argN
+
이 함수에서 공식적인 argument 이름들로 사용되는 이름들이다. 각각은 유효한 Javascript 식별자이거나 쉼표로 구분된 문자열 리스트에 해당되는 문자열이어야 한다; for example "x", "theValue", or "a,b".
+
functionBody
+
함수 정의를 구성하는 JavaScript 문이 포함된 문자열.
+
+ +

Description

+ +

GeneratorFunction 생성자로 생성된 {{jsxref("Statements/function*", "generator function")}} 객체는 그 함수가 생성될 때 분석한다. 이러한 함수들이 나머지 코드들과 함께 분석되기 때문에, {{jsxref("Statements/function*", "function* expression")}}으로 generator function을 선언하고 코드 내에서 호출하는 것보다 덜 효율적입니다.

+ +

그 함수로 전달된 모든 arguments는 생성될 함수 안에서 파라미터의 식별자 이름으로 그것들이 전달된 순서대로 처리된다.

+ +
+

Note: {{jsxref("Statements/function*", "generator function")}} created with the GeneratorFunction constructor do not create closures to their creation contexts; they always are created in the global scope. When running them, they will only be able to access their own local variables and global ones, not the ones from the scope in which the GeneratorFunction constructor was called. This is different from using {{jsxref("Global_Objects/eval", "eval")}} with code for a generator function expression.

+
+ +

new 없이 GeneratorFunction 생성자를 함수처럼 사용하는 것은 생성자처럼 사용하는 것과 동일한 효과를 갖는다.

+ +

Properties

+ +
+
GeneratorFunction.length
+
GeneratorFunction 생성자의 length 속성으로 1 값을 갖는다.
+
{{jsxref("GeneratorFunction.prototype")}}
+
모든 generator function objects 에 속성의 추가를 허용한다.
+
+ +

GeneratorFunction prototype object

+ +

Properties

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction/prototype', 'Properties')}}
+ +

GeneratorFunction instances

+ +

GeneratorFunction 인스턴스는 {{jsxref("GeneratorFunction.prototype")}} 으로부터 속성과 메서드를 상속한다. 다른 모든 생성자들처럼, 생성자의 prototype object 를 변경함으로써 모든 GeneratorFunction instance 에 변화를 줄 수 있다.

+ +

Examples

+ +

GeneratorFunction 생성자로 generator function 생성하기

+ +
var GeneratorFunction = Object.getPrototypeOf(function*(){}).constructor
+var g = new GeneratorFunction("a", "yield a * 2");
+var iterator = g(10);
+console.log(iterator.next().value); // 20
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-generatorfunction-objects', 'GeneratorFunction')}}{{Spec2('ES6')}}Initial definition.
{{SpecName('ESDraft', '#sec-generatorfunction-objects', 'GeneratorFunction')}}{{Spec2('ESDraft')}} 
+ +

Browser compatibility

+ + + +

{{Compat("javascript.builtins.GeneratorFunction")}}

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf