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
appelliert an die Intuition, dass es der Prototyp von asynchronen Generatorobjekten ist.
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 Eigenschaftenattribute:
Eigenschaften von AsyncGeneratorFunction.prototype.prototype | |
---|---|
Schreibbar | ja |
Aufzählbar | nein |
Konfigurierbar | nein |
Beschreibung
Eine asynchrone Generatorfunktion-Instanz hat zwei prototype
-Eigenschaften. Die erste ist ihre eigene prototype
-Eigenschaft. Die zweite ist die prototype
-Eigenschaft auf ihrem Prototyp, der AsyncGeneratorFunction.prototype
ist. (Denken Sie daran, dass jede asynchrone Generatorfunktion eine Instanz von AsyncGeneratorFunction
ist, also AsyncGeneratorFunction.prototype
als 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 Prototyp-Kette einer asynchronen Generatorfunktion und ihrer Instanzen. Jeder hohle Pfeil zeigt eine Vererbungsbeziehung (d.h. eine Prototypverknüpfung) an, und jeder durchgehende Pfeil zeigt eine Eigenschaftsbeziehung an. Beachten Sie, dass es keine Möglichkeit gibt, von gen
auf genFunc
zuzugreifen — sie haben nur eine instanceof
-Beziehung.
Spezifikationen
Specification |
---|
ECMAScript Language Specification # sec-asyncgeneratorfunction-prototype-prototype |
ECMAScript Language Specification # sec-asyncgeneratorfunction-instances-prototype |