docs.rodeo

MDN Web Docs mirror

GeneratorFunction

{{JSRef}} 

The GeneratorFunction object provides methods for generator functions. In JavaScript, every generator function is actually a GeneratorFunction object.

Note that GeneratorFunction is not a global object. It can be obtained with the following code:

const GeneratorFunction = function* () {}.constructor;

GeneratorFunction is a subclass of {{jsxref("Function")}} .

{{InteractiveExample("JavaScript Demo: GeneratorFunction()", "taller")}} 

const GeneratorFunction = function* () {}.constructor;

const foo = new GeneratorFunction(`
  yield 'a';
  yield 'b';
  yield 'c';
`);

let str = "";
for (const val of foo()) {
  str = str + val;
}

console.log(str);
// Expected output: "abc"

Constructor

Instance properties

Also inherits instance properties from its parent {{jsxref("Function")}} .

These properties are defined on GeneratorFunction.prototype and shared by all GeneratorFunction instances.

These properties are own properties of each GeneratorFunction instance.

Instance methods

Inherits instance methods from its parent {{jsxref("Function")}} .

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN