大网数据广告活动
Web 标准与前端开发

GeneratorFunction.prototype.prototype

· 52CE 我爱测

The **`prototype`** property of `GeneratorFunction.prototype` is shared by all generator functions. Its value is `Generator.prototype`. Each generator function created with the `function*` syntax or the `GeneratorFunction()` constructor also has its own `prototype` property, whos

The prototype property of GeneratorFunction.prototype is shared by all generator functions. Its value is Generator.prototype. Each generator function created with the function* syntax or the GeneratorFunction() constructor also has its own prototype property, whose prototype is GeneratorFunction.prototype.prototype. When the generator function is called, its prototype property becomes the prototype of the returned generator object.

Value

The same object as Generator.prototype. GeneratorFunction.prototype.prototype is the technically more accurate name, but Generator.prototype appeals to the intuition that it's the prototype of generator objects.

The prototype property of each GeneratorFunction instance is an empty object with no properties, whose prototype is GeneratorFunction.prototype.prototype. It has the following property attributes:

Description

A generator function instance has two prototype properties. The first one is its own prototype property. The second one is the prototype property on its prototype, which is GeneratorFunction.prototype. (Remember that every generator function is an instance of GeneratorFunction, so it has GeneratorFunction.prototype as its prototype.)

function* genFunc() {}
const GeneratorFunctionPrototype = Object.getPrototypeOf(genFunc);
console.log(Object.hasOwn(genFunc, "prototype")); // true
console.log(Object.hasOwn(GeneratorFunctionPrototype, "prototype")); // true

When a generator function is called, the generator function's prototype property becomes the prototype of the returned generator object.

const gen = genFunc();
const proto = Object.getPrototypeOf;
console.log(proto(gen) === genFunc.prototype); // true
console.log(proto(proto(gen)) === GeneratorFunctionPrototype.prototype); // true

The following diagram illustrates the prototype chain of a generator function and its instances. Each hollow arrow indicates an inheritance relationship (i.e., a prototype link), and each solid arrow indicates a property relationship. Note that there's no way to access genFunc from gen — they only have an instanceof relationship.

The inheritance diagram of generators and generator functions

Specifications

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。