Skip to content

Instantly share code, notes, and snippets.

@dwiyatci
Last active April 17, 2020 22:44
Show Gist options
  • Save dwiyatci/e1008ea0aaa12ba639dd9de415de6fcd to your computer and use it in GitHub Desktop.
Save dwiyatci/e1008ea0aaa12ba639dd9de415de6fcd to your computer and use it in GitHub Desktop.
function* is not a gen.
function* xcounter() {
let index = 0;
while (true) {
index += 1;
const x = yield index;
console.log(x);
}
}
const xgen = xcounter();
console.log(xgen.next().value);
console.log(xgen.next(42).value);
console.log(xgen.next().value);
function counter() {
let index = 0;
return () => {
index += 1;
return index;
};
}
const gen = counter();
console.log(gen());
console.log(gen());
console.log(gen());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment