ES6 layman -2 new function: the generator 4 iterators and iterator -2.Symbol

symbol

Es5 data type in all the complex types are object types.

ES6 which increases the symbol type, not much useful.


https://zhuanlan.zhihu.com/p/22652486

code optimization does not actually have no problem


you can also write, so writing is not easy to make mistakes.

For example, the word was misspelled so there would be nothing to create.

Write directly on the incorrect report

more than two usages which is good, you see which way to write less error-prone. A string, if misspelled, it is not easy to monitor.

Protoss, family, 123 back into Zerg values are also possible. Concluded that: Protoss, Terran, Zerg behind the value that is not interesting. Simply you do not need to give it a value.
As long as the Protoss, Terran, Zerg is not equal to it. So we have no need to think its value is.

Protoss, Terran, Zerg are assigned to a Symbol type





on the Symbol is to create a unique value. Symbol is a sign. Birthmark can understand human family, which is unique

Iterator

This is the meaning of traversal.

Iteration. A level equivalent to students.
We do not know how many zhihu version. zhihu even themselves do not know how many versions of
iterations is not the next version, if you give me, not just the end of the



method published every call, version to +1, each call will return next version .

Publisher method called once, with a reception, may I ask what is a value?
a is an object that has two properties, which are next and done. This is the first iteration.
next is the next version of the entrance, done that I have not the next version.

done next and are now unfined

Began to transform

The next into a function

is now only one next

if I now call this a.next () does not return anything, because this function is now nothing has been done.

Let function to do something

Inside the function and returning a function

, if run a.next (). It is an object.

Function objects, function objects.

Each call next time _value will increase as the value returned to you 1

object 1 calls a.next eventually return value is.

A.next method called once again, the value becomes a value of 2

that's a done almost on an iterator

Multi return a done

10. The maximum value of 10 was added to stop the iterations. done is true, false otherwise done




not stop, or continue to add 1

more than the maximum will throw an error.



Iterator concept.


To tell the following iterator generator.



 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11815301.html