Commit 6553fb76 authored by David Votrubec's avatar David Votrubec

Added yield example

parent 7b9afcda
"use strict";
// Example of resuming yielded generator and passing in a new variable
function *generator() {
console.log('I have started');
yield; // we yield nothing, so the returned value is undefined
var a = yield "some value";
console.log('a is now ', a); // 'a' will contain value passed into generator when it was resumed
var iterator = generator();
var firstValue =;
// outputs {done: false, value: undefined}
console.log('firstValue', firstValue);
var secondValue =;
// outputs {done: false, value: "some value"}
console.log('secondValue', secondValue);
// resumes the generator, 'a' will now get value from the yield expression
// and outputs it to console
var thirdValue ='bbb');
// outputs {done: true, value: undefined}
console.log('thirdValue', thirdValue);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment