Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- // Iterable class (computed property and generator method syntax)
- const Foo = class Foo {
- *[Symbol.iterator]() {
- yield* [2, 3, 5, 7, 11, 13, 17, 19];
- yield 23;
- };
- get name() {
- return "<<I am Foo>>";
- };
- };
- // usage
- const f = new Foo();
- for (let v of f) {
- console.log(f.name, v);
- }
- // Iterable object
- const bar = {
- *[Symbol.iterator]() {
- yield "u";
- yield* ["a", "t", "g", "c"];
- },
- get name() {
- return "<<I am Bar>>";
- },
- };
- for (let v of bar) {
- console.log(bar.name, v);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement