[Javascript] Create Your First Iterator in JavaScript
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Javascript] Create Your First Iterator in JavaScript相关的知识,希望对你有一定的参考价值。
Iterators are the foundation of generators. Much of the misunderstanding around generators comes from the lack of understanding iterators. An iterator has a Symbol.iterator
property with an object that contains a next
method which defines what is output each iteration.
let i = 0 const next = () => ({ value: i++, done: i > 10 }) const iterator = { [Symbol.iterator]() { return { next } } } for (let value of iterator) { console.log(value) }
以上是关于[Javascript] Create Your First Iterator in JavaScript的主要内容,如果未能解决你的问题,请参考以下文章
[Vue + TS] Create your own Decorators in Vue with TypeScript
[Tools] Create your own mobile emulator device by using Chrome dev tool
GitHub Desktop 出现“please upgrade your plan to create a new private repository”的解决办法
create a cocos2d-x-3.0 project in Xcode
Build Your own Simplified AngularJS in 200 Lines of JavaScript