es6 迭代器

The iterable protocol

The iterable protocol allows JavaScript objects to define or customize their iteration behavior, such as what values are looped over in a for..of construct. Some built-in types are built-in iterables with a default iteration behavior, such as Array or Map, while other types (such as Object) are not.

In order to be iterable, an object must implement the @@iterator method, meaning that the object (or one of the objects up its prototype chain) must have a property with a @@iterator key which is available via constant Symbol.iterator:

Property Value
[Symbol.iterator] A zero arguments function that returns an object, conforming to the iterator protocol.

The iterator protocol

The iterator protocol defines a standard way to produce a sequence of values (either finite or infinite).

An object is an iterator when it implements a next() method with the following semantics:

最近的文章

Eloquent Ruby (Chapter 1) 手记

1. 代码的优美从缩进开始:Ruby的代码缩进约定: 2个空格。 只用2个空格。2. Go Easy on the Comments注释的时候悠着点儿Ruby的注释很简单:#符号后面的任何代码都是注释。但是真正的问题是:什么时候该注释,多少注释才够?好的Ruby代码是不需要去写注释的。代码应该能够自己解释自己。当需要注释的时候,最好去解释,这些代码如何去用就够了。而不是你为什么要写它,以及它的算法,或者是你如何使它越来越快。只需要告诉我们,如何去用,能记住下面注释例子就更好了:# Clas...…

继续阅读
更早的文章

Dom Tree & Render Tree

webgl canvas继续阅读