generator-function
v1.0.0
Published
Expose the GeneratorFunction constructor if supported by the runtime
Downloads
3
Readme
generator-function
Expose the ES2015 GeneratorFunction
constructor.
Installation
npm install generator-function
Description
Like Function
s, one could create generator functions from a JavaScript string
through a special constructor called GeneratorFunction
. However, the
constructor function is not available as a global, so one has to use the
constructor
property of an existing generator function.
This module makes it easy to do so, and falls back gracefully when a runtime not supporting generator functions is encountered.
Usage
On a platform supporting generator functions:
var GeneratorFunction = require('generator-function')
var generatorFunction = new GeneratorFunction('arg1', 'yield arg1')
var generator = generatorFunction(1)
generator.next()
//=> { value: 1, done: false }
generator.next()
//=> { value: undefined, done: true }
On a runtime that does not support them:
var GeneratorFunction = require('generator-function')
GeneratorFunction
// => undefined
License
MIT