GeneratorFunction() Konstruktor
        
        
          
                Baseline
                
                  Widely available
                
                
              
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
Der GeneratorFunction()-Konstruktor erstellt GeneratorFunction Objekte.
Beachten Sie, dass GeneratorFunction kein globales Objekt ist. Es kann mit dem folgenden Code erlangt werden:
js
const GeneratorFunction = function* () {}.constructor;
Der GeneratorFunction()-Konstruktor ist nicht dazu gedacht, direkt verwendet zu werden, und alle in der Function()-Beschreibung erwähnten Warnungen gelten auch für GeneratorFunction().
Syntax
js
new GeneratorFunction(functionBody)
new GeneratorFunction(arg1, functionBody)
new GeneratorFunction(arg1, arg2, functionBody)
new GeneratorFunction(arg1, arg2, /* …, */ argN, functionBody)
GeneratorFunction(functionBody)
GeneratorFunction(arg1, functionBody)
GeneratorFunction(arg1, arg2, functionBody)
GeneratorFunction(arg1, arg2, /* …, */ argN, functionBody)
Hinweis:
GeneratorFunction() kann mit oder ohne new aufgerufen werden. Beide Varianten erzeugen eine neue Instanz von GeneratorFunction.
Parameter
Siehe Function().
Beispiele
>Erstellen und Verwenden eines GeneratorFunction()-Konstruktors
js
const GeneratorFunction = function* () {}.constructor;
const g = new GeneratorFunction("a", "yield a * 2");
const iterator = g(10);
console.log(iterator.next().value); // 20
Spezifikationen
| Specification | 
|---|
| ECMAScript® 2026 Language Specification> # sec-generatorfunction-constructor> | 
Browser-Kompatibilität
Loading…