๐ฐgenerator function as ...
JS โฉ objects โฉ built-in โฉ Generator โฉ generator function โฉ as ...
// โญ๏ธ function* expressions
// โญโโโโโโโ ๐ธ 1. as "variable" โโโโโโโโฎ
const f = function*() { yield 'a'; yield 'b'; };
// โฐโโโโโโโโโโโโโโ const statement โโโโโโโโโโโโโโโโฏ
let obj = {
// (part of) keys
x: 1, y: 2, z: 3,
//โญโโโโโโโโโโโโโโโ ๐ธ 2. as "method" โโโโโโโโโโโโโโโโฎ
*keys() {
for (let key of Object.keys(this)) { yield key }
}
};
// 1. as variable
[...f()] // [ 'a', 'b' ]
// 2. as method
[...obj.keys()] // [ 'x', 'y', 'z', 'keys' ]