practical-modern-javascript icon indicating copy to clipboard operation
practical-modern-javascript copied to clipboard

Spread Operator Syntax for Objects

Open jameshbush opened this issue 6 years ago • 3 comments

This section suggests the Spread Operator syntax only works for iterable object literals. In fact, generic Object literal declarations also support spread operator assignment syntax:

"Note that the spread operator isn’t limited to arrays and arguments. The spread operator can be used with any iterable object. Iterable is a protocol in ES6 that allows you to turn any object into something that can be iterated over. We’ll research the iterable protocol in Iteration and Flow Control."

Screen Shot 2019-06-16 at 09 41 20

Is there another section where non-iterable Object Literal spread syntax is covered?

jameshbush avatar Jun 16 '19 13:06 jameshbush

Object spread wasn’t part of the language until ES2018; and it applies to any object, iterable or not (mst objects aren’t iterable, including your two examples)

ljharb avatar Jun 16 '19 16:06 ljharb

Thanks for the explanation @ljharb

I'm missing a lot of context about the evolution ofJavaScript. This book is a great asset to the community. Thanks.

jameshbush avatar Jun 16 '19 17:06 jameshbush

We could add a note that clarifies this for future readers? @jajajames want to PR that up? 🎉

bevacqua avatar Jun 19 '19 18:06 bevacqua