THE PRIMITIVE TYPE SYMBOL
Symbol is a new JS data primitive introduced with the 2015 ECMA specification (ES6). A symbol represents a unique and anonymous value. To create them, we cannot use literal syntax but use the type Symbol. Symbols are very useful when we want to avoid property conflicts on an object. Another example of use is when we want to pass a unique, nonreplicable value to a function.
SAMPLE CODE
IMPLEMENT ITERATOR PROTOCOL
An iterator to be such must be able to access a sequence of elements one at a time. Having implemented the Iterator protocol does not mean that we can scroll through, for example, an array with a for of.
IMPLEMENT THE ITERABLE PROTOCOL
An Iterable object allows us to customize how a sequence is traversed, such as through a for loop of. The Iterable protocol must implement a property next whose value is a function.
ASYNC ITERATOR
We can implement the Iterable protocol with an asynchronous Iterator.
INTRODUCTION TO GENERATORS
Functions as we know are a block of code executed in full or at any rate, up to the return. With generators we have a partial mechanism for executing function code. We can start the function and perform the stop at a certain point. We run one portion of the function, then another portion, and so on, all with internal state maintenance.
IMPORT AND EXPORT VALUES FROM A GENERATOR (CODE)
CREATE AN INFINITE ITERATOR WITH GENERATORS
The generators implement the Iterable and Iterator protocols, since they implement Iterable we can use a for of to iterate over the elements.
Leave A Comment