AsyncGeneratorFunction
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.
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:
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 += val;
}
console.log(str);
}
generate();
// Expected output: "abc"
Konstruktor
AsyncGeneratorFunction()-
Erstellt ein neues
AsyncGeneratorFunction-Objekt.
Instanz-Eigenschaften
Erbt auch Instanz-Eigenschaften von seinem Elternobjekt 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 derAsyncGeneratorFunction-Konstruktor. AsyncGeneratorFunction.prototype.prototype-
Alle asynchronen Generatorfunktionen teilen die gleiche
prototype-Eigenschaft, dieAsyncGenerator.prototypeist. Jede asynchrone Generatorfunktion, die mit derasync function*-Syntax oder demAsyncGeneratorFunction()-Konstruktor erstellt wird, hat auch ihre eigeneprototype-Eigenschaft, deren PrototypAsyncGeneratorFunction.prototype.prototypeist. Wenn die asynchrone Generatorfunktion aufgerufen wird, wird ihreprototype-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 inObject.prototype.toString()verwendet.
Diese Eigenschaften sind eigene Eigenschaften jeder AsyncGeneratorFunction-Instanz.
Instanz-Methoden
Erbt Instanz-Methoden von seinem Elternobjekt Function.
Spezifikationen
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-asyncgeneratorfunction-objects> |
Browser-Kompatibilität
Loading…