Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created March 13, 2011 20:09
Show Gist options
  • Save joseanpg/868387 to your computer and use it in GitHub Desktop.
Save joseanpg/868387 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()+', the deep yield give-out Hola and give-in undefined');
console.log(gen.next()+', now shallow yield return that undefined');
console.log(gen.next()+', now the deep yield: Hola out, undefined in');
console.log(gen.next()+', now the shallow yield: undefined');
console.log(gen.next()+', now the deep yield: Hola out, undefined in');
console.log(gen.next()+', now the shallow yield: undefined');
console.log(gen.next()+', now the deep yield: Hola out, undefined in');
console.log(gen.next()+', now the shallow yield: undefined');
/**
Pythonic behavior
-----------------
Hola 1, the deep yield give-out Hola and give-in undefined
undefined, now shallow yield return that undefined
Hola 2, now the deep yield: Hola out, undefined in
undefined, now the shallow yield: undefined
Hola 3, now the deep yield: Hola out, undefined in
undefined, now the shallow yield: undefined
Hola 4, now the deep yield: Hola out, undefined in
undefined, now the shallow yield: undefined
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment