Javascript - Collection Generators


Generators are functions that can be paused.

A generator is a function that creates a special type of iterator.

Its execution can be suspended and retained while keeping the context.

A function is a generator if it contains one or more yield expressions and if it uses the function * syntax:

function *gen() { 
    yield 2; 

A generator can be written in any of the following ways:

function *gen()  { .. } 
function* gen()  { .. } 
function * gen() { .. } 
function*gen()   { .. } 

Related Topics