GeneratorFunction() 构造函数
GeneratorFunction() 构造函数创建 GeneratorFunction 对象。
¥The GeneratorFunction() constructor creates GeneratorFunction objects.
请注意,GeneratorFunction 不是全局对象。可以通过以下代码获取:
¥Note that GeneratorFunction is not a global object. It can be obtained with the following code:
js
const GeneratorFunction = function* () {}.constructor;
GeneratorFunction() 构造函数不适合直接使用,Function() 描述中提到的所有注意事项均适用于 GeneratorFunction()。
¥The GeneratorFunction() constructor is not intended to be used directly, and all caveats mentioned in the Function() description apply to GeneratorFunction().
语法
¥Syntax
js
new GeneratorFunction(functionBody)
new GeneratorFunction(arg1, functionBody)
new GeneratorFunction(arg1, arg2, functionBody)
new GeneratorFunction(arg1, arg2, /* …, */ argN, functionBody)
GeneratorFunction(functionBody)
GeneratorFunction(arg1, functionBody)
GeneratorFunction(arg1, arg2, functionBody)
GeneratorFunction(arg1, arg2, /* …, */ argN, functionBody)
注意:可以使用或不使用
new来调用GeneratorFunction()。两者都会创建一个新的GeneratorFunction实例。¥Note:
GeneratorFunction()can be called with or withoutnew. Both create a newGeneratorFunctioninstance.
参数
示例
创建和使用 GeneratorFunction() 构造函数
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-generatorfunction-constructor |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also