1

Jumping from regular old js with ang1 to ang2 with typescript and redux etc is a heck of a steep climb.

Could anyone offer a simple explanation to the ... syntax? Having come from a php and javascript background this is really new stuff.

http://blog.ng-book.com/introduction-to-redux-with-typescript-and-angular-2/#deleting-an-item-without-mutation shows this as an example with redux:

return {
      messages: [
        ...state.messages.slice(0, idx),
        ...state.messages.slice(idx + 1, state.messages.length)
      ]

But does anyone have an uber simple example for a complete noob to this area? Feels like i'm going round in circles!

1 Answers1

0

The three dots represent the rest operator and it is used to get the arguments list passed to function on invocation and in array destructure. A case when the operator gathers the rest remained after the operation.

The spread operator is used for array construction and destructuring, and to fill function arguments from an array on invocation. A case when the operator spreads the array (or iterable object) elements.

You can read more about this here.

Ionut Necula
  • 11,107
  • 4
  • 45
  • 69
  • This is somehow messed up, spread is never used in destructuring - only in array literals and function calls. Btw, you shouldn't call it an "operator" since technically it isn't one, we prefer the terms "rest parameter" and "spread syntax". – Bergi Oct 28 '16 at 12:13