Javascript Iterator

1、@@iterator

  Whenever an object needs to be iterated (such as at the beginning of a for..of loop), its @@iteratormethod is called with no arguments, and the returned iterator is used to obtain the values to be iterated.

  Javascript Iterator

  示例:

  Javascript Iterator

  指定的方法必须是funtion*,否则出错

  Javascript Iterator

2、for...of

  Whenever an object needs to be iterated (such as at the beginning of a for..of loop), its @@iteratormethod is called with no arguments, and the returned iterator is used to obtain the values to be iterated.

3、The iterator protocol

  Javascript Iterator

参考:

1、https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator

2、https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols

相关文章:

  • 2022-12-23
  • 2022-03-03
  • 2021-10-17
  • 2021-10-04
猜你喜欢
  • 2022-02-20
  • 2021-12-20
  • 2021-10-04
  • 2021-08-29
相关资源
相似解决方案