Constructor
new Generator(func, …args)
Creates a new Generator from a given Function and its arguments. If a specific "this" object is desired to be
used with func, func=func.bind(someThisObject) should be set before calling this constructor.
Parameters:
Name |
Type |
Attributes |
Description |
func |
function
|
|
A Function that contains yields. |
args |
*
|
<repeatable>
|
The arguments that will be passed to the Function |
Members
name
Gets the name of this Generator object. This is set to the Function's name upon instantiation.
returnValue
This property has nothing to do with the return method. In Mildew, deviating from other languages, Generator functions may
have return statements and a return value. This property extracts the return value once the Generator is finished, otherwise
it returns undefined.
Methods
next(value) → {Object}
Run the generator one time and get the next yield.
Parameters:
Name |
Type |
Description |
value |
*
|
If yield is used as the right hand side of an assignment, this value will be the result. |
Returns:
An Object containing the following fields: "value", which is the last yielded value, or could be undefined
if the Generator is done, and "done", a boolean of true or false indicating whether or not the Generator can be run any further.
-
Type
-
Object
return(value) → {Object}
Runs the Generator to completion and returns the value that was sent.
Parameters:
Name |
Type |
Description |
value |
*
|
The value to serve as the "value" field in the return value Object. |
Returns:
An object containing a "value" field set to the parameter, and "done" which is always set to true.
-
Type
-
Object
throw(error) → {Object}
Similar to next(), but causes the Generator to throw an error on its next yield. If this error is not caught inside the Generator function
it will propagate to the call site of throw. It is an error to call throw on a finished Generator.
Parameters:
Name |
Type |
Description |
error |
*
|
Any value to serve as the error being thrown. |
Returns:
An object containing a possible "value" field and a "done" field that is either true or false.
-
Type
-
Object