Last active
April 17, 2020 22:44
-
-
Save dwiyatci/e1008ea0aaa12ba639dd9de415de6fcd to your computer and use it in GitHub Desktop.
function* is not a gen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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