AsyncGeneratorFunction() Konstruktor
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Januar 2020.
Der AsyncGeneratorFunction() Konstruktor erstellt AsyncGeneratorFunction Objekte.
Beachten Sie, dass AsyncGeneratorFunction kein globales Objekt ist. Es kann durch die Auswertung des folgenden Codes erhalten werden.
const AsyncGeneratorFunction = async function* () {}.constructor;
Der AsyncGeneratorFunction() Konstruktor ist nicht dafür vorgesehen, direkt verwendet zu werden, und alle in der Function() Beschreibung erwähnten Einschränkungen gelten für AsyncGeneratorFunction().
Syntax
new AsyncGeneratorFunction(functionBody)
new AsyncGeneratorFunction(arg1, functionBody)
new AsyncGeneratorFunction(arg1, arg2, functionBody)
new AsyncGeneratorFunction(arg1, arg2, /* …, */ argN, functionBody)
AsyncGeneratorFunction(functionBody)
AsyncGeneratorFunction(arg1, functionBody)
AsyncGeneratorFunction(arg1, arg2, functionBody)
AsyncGeneratorFunction(arg1, arg2, /* …, */ argN, functionBody)
Hinweis:
AsyncGeneratorFunction() kann mit oder ohne new aufgerufen werden. Beide erzeugen eine neue AsyncGeneratorFunction Instanz.
Parameter
Siehe Function().
Beispiele
>Verwendung des Konstruktors
Das folgende Beispiel verwendet den AsyncGeneratorFunction Konstruktor, um eine asynchrone Generatorfunktion zu erstellen.
const AsyncGeneratorFunction = async function* () {}.constructor;
const createAsyncGenerator = new AsyncGeneratorFunction("a", "yield a * 2");
const asyncGen = createAsyncGenerator(10);
asyncGen.next().then((res) => console.log(res.value)); // 20
Spezifikationen
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-asyncgeneratorfunction-constructor> |