Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created March 13, 2011 20:28
Show Gist options
  • Save joseanpg/868406 to your computer and use it in GitHub Desktop.
Save joseanpg/868406 to your computer and use it in GitHub Desktop.
//script type="application/javascript;version=1.7"
function GenMaker() {
let(j=1){for(;;) {yield (yield 'Hola '+j);j++}}
}
var gen = GenMaker();
console.log(gen.next());
console.log(gen.send('Adios'));
console.log(gen.send(null));
console.log(gen.send('Adios'));
console.log(gen.send(null));
console.log(gen.send('Adios'));
console.log(gen.send(null));
/**
Pythonic behavior
-----------------
Hola 1
Adios
Hola 2
Adios
Hola 3
Adios
Hola 4
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment