Example 1 — Example
Typical usage.
JavaScript
function* g() { yield 1; }
console.log(g.constructor.name);
console.log(g().next().value);How It Works
- function*. Creates a generator function.
- constructor.name. GeneratorFunction.
GeneratorFunction is the constructor of generator functions. Prefer function* syntax; the constructor is mainly for advanced metaprogramming.
function* g() { yield 1; }
console.log(g.constructor.name);
console.log(g().next().value);Typical usage.
function* g() { yield 1; }
console.log(g.constructor.name);
console.log(g().next().value);Check browser support for newer APIs.
console.log("GeneratorFunction — see MDN for support tables");CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful