Generator - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

generator function

The Generator object is returned by a generator function and it conforms to both the iterable protocol and the iterator protocol.

GeneratorFunction.prototype.prototype

There's no JavaScript entity that corresponds to the Generator constructor. Instances of Generator must be returned from generator functions:

Generator.prototype.constructor

The constructor function that created the instance object. For Generator instances, the initial value is GeneratorFunction.prototype.

GeneratorFunction.prototype

The constructor function that created the instance object. For Generator instances, the initial value is GeneratorFunction.prototype.

[Symbol.toStringTag]

The initial value of the [Symbol.toStringTag] property is the string "Generator". This property is used in Object.prototype.toString().

Object.prototype.toString()

The initial value of the [Symbol.toStringTag] property is the string "Generator". This property is used in Object.prototype.toString().

Generator.prototype.next()

Acts as if a return statement is inserted in the generator's body at the current suspended position, which finishes the generator and allows the generator to perform any cleanup tasks when combined with a try...finally b

Generator.prototype.return()

Acts as if a return statement is inserted in the generator's body at the current suspended position, which finishes the generator and allows the generator to perform any cleanup tasks when combined with a try...finally b

Generator.prototype.throw()

Acts as if a return statement is inserted in the generator's body at the current suspended position, which finishes the generator and allows the generator to perform any cleanup tasks when combined with a try...finally b

function* expression

Iteration protocols

Learn how to contribute

This page was last modified on Jan 24, 2026 by MDN contributors.

[Symbol.dispose]()

[Symbol.iterator]()

[Symbol.hasInstance]()

__defineGetter__()