Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Last active November 25, 2016 00:36
Show Gist options
  • Save gkucmierz/a566a9ab2d7f717443630ad43b388d8c to your computer and use it in GitHub Desktop.
Save gkucmierz/a566a9ab2d7f717443630ad43b388d8c to your computer and use it in GitHub Desktop.
Implementation of new generator creation from string
let Generator = (function*(){}).constructor;
// function Generator(...a) {
// let [args, body] = a;
// if (a.length === 0) [args, body] = [[], ''];
// if (a.length === 1) [args, body] = [[], a[0]];
// return new Function(`return function*(${args.join(',')}){${body}};`)();
// }
// new genearator:
//
// new Generator();
// new Generator('return yield;');
// new Generator(['arg'], 'return yield arg;');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment