29_Generator.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // function* foo(){
  11. // console.log('start');
  12. // yield;
  13. // console.log("1");
  14. // yield;
  15. // console.log("2");
  16. // }
  17. // let g = foo();
  18. // g.next();
  19. // g.next();
  20. // g.next();
  21. // function* foo(){
  22. // let a = 1;
  23. // let b = yield a + 3;
  24. // console.log(111);
  25. // console.log(b);
  26. // }
  27. // let g = foo();
  28. // let {value} =g.next();
  29. // console.log(g.next(value));
  30. // function* foo(x) {
  31. // var y = 2 * (yield (x + 1));
  32. // console.log(y);
  33. // var z = yield (y / 3);
  34. // return (x + y + z);
  35. // }
  36. // let foo2 = foo(1);
  37. // console.log(foo2.next());
  38. // console.log(foo2.next(3));
  39. // console.log(foo2.next(1));
  40. </script>
  41. </body>
  42. </html>