• iterator迭代器
      1. const obj = {
      2. data:["hello", "world"],
      3. [Symbol.iterator]() {
      4. const self = this;
      5. let index = 0;
      6. return {
      7. next() {
      8. if (index < self.data.length) {
      9. return {
      10. value:self.data[index++],
      11. done:false
      12. }
      13. } else {
      14. return {value:undefined, done:true}
      15. }
      16. }
      17. }
      18. }
      19. }
      20. for (let o of obj) {
      21. console.log(o);
      22. }