AsyncGeneratorFunction

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Das AsyncGeneratorFunction-Objekt stellt Methoden für asynchrone Generatorfunktionen bereit. In JavaScript ist jede asynchrone Generatorfunktion tatsächlich ein AsyncGeneratorFunction-Objekt.

Beachten Sie, dass AsyncGeneratorFunction kein globales Objekt ist. Es kann mit dem folgenden Code erhalten werden:

js
const AsyncGeneratorFunction = async function* () {}.constructor;

AsyncGeneratorFunction ist eine Unterklasse von Function.

Probieren Sie es aus

const AsyncGeneratorFunction = async function* () {}.constructor;

const foo = new AsyncGeneratorFunction(`
  yield await Promise.resolve('a');
  yield await Promise.resolve('b');
  yield await Promise.resolve('c');
`);

let str = "";

async function generate() {
  for await (const val of foo()) {
    str = str + val;
  }
  console.log(str);
}

generate();
// Expected output: "abc"

Konstruktor

AsyncGeneratorFunction()

Erstellt ein neues AsyncGeneratorFunction-Objekt.

Instanz-Eigenschaften

Erbt auch Instanz-Eigenschaften von seinem Elternteil Function.

Diese Eigenschaften sind auf AsyncGeneratorFunction.prototype definiert und werden von allen AsyncGeneratorFunction-Instanzen geteilt.

AsyncGeneratorFunction.prototype.constructor

Die Konstruktorfunktion, die das Instanzobjekt erstellt hat. Für AsyncGeneratorFunction-Instanzen ist der Anfangswert der AsyncGeneratorFunction-Konstruktor.

AsyncGeneratorFunction.prototype.prototype

Alle asynchronen Generatorfunktionen teilen die gleiche prototype-Eigenschaft, die AsyncGenerator.prototype ist. Jede asynchrone Generatorfunktion, die mit der async function*-Syntax oder dem AsyncGeneratorFunction()-Konstruktor erstellt wurde, hat auch ihre eigene prototype-Eigenschaft, deren Prototyp AsyncGeneratorFunction.prototype.prototype ist. Wenn die asynchrone Generatorfunktion aufgerufen wird, wird ihre prototype-Eigenschaft zum Prototyp des zurückgegebenen asynchronen Generatorobjekts.

AsyncGeneratorFunction.prototype[Symbol.toStringTag]

Der Anfangswert der [Symbol.toStringTag]-Eigenschaft ist der String "AsyncGeneratorFunction". Diese Eigenschaft wird in Object.prototype.toString() verwendet.

Diese Eigenschaften sind eigene Eigenschaften jeder AsyncGeneratorFunction-Instanz.

prototype

Wird verwendet, wenn die Funktion als Konstruktor mit dem new-Operator verwendet wird. Es wird zum Prototyp des neuen Objekts.

Instanz-Methoden

Erbt Instanz-Methoden von seinem Elternteil Function.

Spezifikationen

Specification
ECMAScript® 2026 Language Specification
# sec-asyncgeneratorfunction-objects

Browser-Kompatibilität

Siehe auch