Skip to content

Instantly share code, notes, and snippets.

@Mayankgupta688
Last active May 17, 2019 07:39
Show Gist options
  • Select an option

  • Save Mayankgupta688/55f3696583e592cd7c705187bd6606c9 to your computer and use it in GitHub Desktop.

Select an option

Save Mayankgupta688/55f3696583e592cd7c705187bd6606c9 to your computer and use it in GitHub Desktop.
function* customGenerator() {
let x = yield 1;
yield x + 1
}
let getIterator = customGenerator();
let nextValue = null;
nextValue = getIterator.next();
console.log(nextValue);
// Output is: { value: 1, done: false }
nextValue = getIterator.next(10);
console.log(nextValue);
// Output is: { value: 11, done: false }
nextValue = getIterator.next();
console.log(nextValue);
// Output is: { value: undefined, done: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment