AsyncGeneratorFunction.prototype.prototype
Die prototype
-Eigenschaft von AsyncGeneratorFunction.prototype
wird von allen asynchronen Generatorfunktionen gemeinsam genutzt. Ihr Wert ist AsyncGenerator.prototype
. Jede asynchrone Generatorfunktion, die mit der async function*
-Syntax oder dem AsyncGeneratorFunction()
-Konstruktor erstellt wurde, hat ebenfalls 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 exaktere Name, aber AsyncGenerator.prototype
spricht die Intuition an, dass es sich um den Prototyp von asynchronen Generatorobjekten 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. Sie hat die folgenden Eigenschaften Attribute:
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 in ihrem Prototyp, was 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 Prototypkette einer asynchronen Generatorfunktion und ihrer Instanzen. Jeder hohle Pfeil zeigt eine Vererbungsbeziehung (d.h. einen Prototyp-Link) an, und jeder solide Pfeil zeigt eine Eigenschaften-Beziehung an. Beachten Sie, dass es keine Möglichkeit gibt, 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 |