AsyncGeneratorFunction.prototype.prototype
Die prototype-Eigenschaft von AsyncGeneratorFunction.prototype wird von allen asynchronen Generatorfunktionen geteilt. Ihr Wert ist AsyncGenerator.prototype. 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.
Wert
Dasselbe Objekt wie AsyncGenerator.prototype. AsyncGeneratorFunction.prototype.prototype ist der technisch genauere Name, aber AsyncGenerator.prototype entspricht eher der Intuition, dass es sich um den Prototyp asynchroner Generatorobjekte handelt.
Eigenschaften von AsyncGeneratorFunction.prototype.prototype | |
|---|---|
| Schreibbar | nein |
| Aufzählbar | nein |
| Konfigurierbar | ja |
Die prototype-Eigenschaft jeder AsyncGeneratorFunction-Instanz ist ein leeres Objekt ohne Eigenschaften, dessen Prototyp AsyncGeneratorFunction.prototype.prototype ist. Es hat die folgenden Eigenschaftsattribute:
Eigenschaften von AsyncGeneratorFunction.prototype.prototype | |
|---|---|
| Schreibbar | ja |
| Aufzählbar | nein |
| Konfigurierbar | nein |
Beschreibung
Eine Instanz einer asynchronen Generatorfunktion hat zwei prototype-Eigenschaften. Die erste ist ihre eigene prototype-Eigenschaft. Die zweite ist die prototype-Eigenschaft auf ihrem Prototyp, die AsyncGeneratorFunction.prototype ist. (Denken Sie daran, dass jede asynchrone Generatorfunktion eine Instanz von AsyncGeneratorFunction ist, sodass sie AsyncGeneratorFunction.prototype als ihren Prototyp hat.)
async function* genFunc() {}
const AsyncGeneratorFunctionPrototype = Object.getPrototypeOf(genFunc);
console.log(Object.hasOwn(genFunc, "prototype")); // true
console.log(Object.hasOwn(AsyncGeneratorFunctionPrototype, "prototype")); // true
Wenn eine asynchrone Generatorfunktion aufgerufen wird, wird die prototype-Eigenschaft der asynchronen Generatorfunktion zum Prototyp des zurückgegebenen asynchronen Generatorobjekts.
const gen = genFunc();
const proto = Object.getPrototypeOf;
console.log(proto(gen) === genFunc.prototype); // true
console.log(proto(proto(gen)) === AsyncGeneratorFunctionPrototype.prototype); // true
Das folgende Diagramm veranschaulicht die Prototypenkette einer asynchronen Generatorfunktion und ihrer Instanzen. Jede hohle Pfeil zeigt eine Vererbungsbeziehung (d.h. einen Prototyp-Link) an, und jeder durchgezogene Pfeil zeigt eine Eigenschaftsbeziehung an. Beachten Sie, dass es keinen direkten Weg gibt, um von gen auf genFunc zuzugreifen — sie haben nur eine instanceof-Beziehung.
Spezifikationen
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-asyncgeneratorfunction-prototype-prototype> |
| ECMAScript® 2026 Language Specification> # sec-asyncgeneratorfunction-instances-prototype> |