This is an experimental technology, part of the ECMAScript 6 (Harmony) proposal.Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.

Legacy generator objects

Firefox (SpiderMonkey) also implements an earlier version of generators in JavaScript 1.7. There is no need for the star (*) in the function declaration, you just use the yield keyword in the function body. However, legacy generators are deprecated. Do not use them; they are going to be removed (bug 1083482).

Legacy generator methods

Generator.prototype.next()

Returns a value yielded by the yield expression. This corresponds to next() in the ES6 generator object.

Generator.prototype.close()

Closes the generator, so that when calling next() an StopIteration error will be thrown. This corresponds to the return() method in the ES6 generator object.

Generator.prototype.send()

Used to send a value to a generator. The value is returned from the yield expression, and returns a value yielded by the next yield expression. send(x) corresponds to next(x) in the ES6 generator object.

Generator.prototype.throw()

Throws an error to a generator. This corresponds to the throw() method in the ES6 generator object.