Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. "use strict";
  2.  
  3. // Iterable class (computed property and generator method syntax)
  4. const Foo = class Foo {
  5. *[Symbol.iterator]() {
  6. yield* [2, 3, 5, 7, 11, 13, 17, 19];
  7. yield 23;
  8. };
  9. get name() {
  10. return "<<I am Foo>>";
  11. };
  12. };
  13.  
  14. // usage
  15. const f = new Foo();
  16. for (let v of f) {
  17. console.log(f.name, v);
  18. }
  19.  
  20. // Iterable object
  21. const bar = {
  22. *[Symbol.iterator]() {
  23. yield "u";
  24. yield* ["a", "t", "g", "c"];
  25. },
  26. get name() {
  27. return "<<I am Bar>>";
  28. },
  29. };
  30.  
  31. for (let v of bar) {
  32. console.log(bar.name, v);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement