ES2018: Async Iteration and More
This lesson covers the new features introduced in ES2018
We'll cover the following...
Rest / Spread for Objects
ES6 (ES2015) allowed us to do this?
Now we can use the rest/spread syntax for objects too, let’s look at how:
With the spread operator we can easily create a clone of our Object so that when we modify the original Object, the clone does not get modified.
Asynchronous iteration
With asynchronous iteration we can iterate asynchronously over our data.
An async iterator is much like an iterator, except that its
next()method returns a promise for a{ value, done }pair.
To do so, we will use a for-await-of loop which works by converting our iterables to a promise, unless they already are one.
During execution, an async iterator is created from the data source using the
[Symbol.asyncIterator]()method. Each time we access the next value in the sequence, we implicitly await the promise returned from the iterator method.