GeneratorFunction
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2016ë 9ìâ©.
GeneratorFunction ìì±ìë ìë¡ì´ generator function ê°ì²´ë¥¼ ìì±íë¤. JavaScript ìì 모ë generator function ì ì¤ì ë¡ GeneratorFunction object ì´ë¤.
주ìí ì ì, GeneratorFunction ì´ ì ì ê°ì²´(global object)ê° ìëë ì ì´ë¤. GeneratorFunctionì ë¤ìì ì½ë를 ì¤íí´ì ì»ì ì ìë¤.
Object.getPrototypeOf(function* () {}).constructor;
Syntax
new Function(arg1, functionBody)
new Function(arg1, arg2, functionBody)
new Function(arg1, ... , argN, functionBody)
Parameters
arg1, arg2, ... argN-
ì´ í¨ììì ê³µìì ì¸ argument ì´ë¦ë¤ë¡ ì¬ì©ëë ì´ë¦ë¤ì´ë¤. ê°ê°ì ì í¨í Javascript ìë³ìì´ê±°ë ì¼íë¡ êµ¬ë¶ë 문ìì´ ë¦¬ì¤í¸ì í´ë¹ëë 문ìì´ì´ì´ì¼ íë¤; for example "
x", "theValue", or "a,b". functionBody-
í¨ì ì ì를 구ì±íë JavaScript ë¬¸ì´ í¬í¨ë 문ìì´.
Description
GeneratorFunction ìì±ìë¡ ìì±ë generator function ê°ì²´ë ê·¸ í¨ìê° ìì±ë ë ë¶ìíë¤. ì´ë¬í í¨ìë¤ì´ ëë¨¸ì§ ì½ëë¤ê³¼ í¨ê» ë¶ìë기 ë문ì, function* expressionì¼ë¡ generator functionì ì ì¸íê³ ì½ë ë´ìì í¸ì¶íë ê²ë³´ë¤ ë í¨ì¨ì ì
ëë¤.
ê·¸ í¨ìë¡ ì ë¬ë 모ë argumentsë ìì±ë í¨ì ììì íë¼ë¯¸í°ì ìë³ì ì´ë¦ì¼ë¡ ê·¸ê²ë¤ì´ ì ë¬ë ììëë¡ ì²ë¦¬ëë¤.
ì°¸ê³ :
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 eval with code for a generator function expression.
new ìì´ GeneratorFunction ìì±ì를 í¨ìì²ë¼ ì¬ì©íë ê²ì ìì±ìì²ë¼ ì¬ì©íë ê²ê³¼ ëì¼í í¨ê³¼ë¥¼ ê°ëë¤.
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
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2026 Language Specification > # sec-generatorfunction-objects > |