Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  > Splats (spreads?)

  >    f(...[1,2,3]) == 6

  > ... means destructure?
No, it means something very close to "apply" or "concat", depending on the usage. That example is the same as:

  f.apply(this, [1,2,3])
But it's cleaner syntax. The interesting part is that you can mix them in anywhere:

  function f(x, y, z) {
    return x + y + z;
  }
  a = [1,2];
  b = [3];

  [...a, ...b] == [].concat(a,b) == [1,2,3]
  [0, ...a, 4, 5, ...b, 6] == [].concat([0],a,[4,5],b,[6]) == [0,1,2,4,5,3,6]
  f(...a, ...b) == 6
  f(1, 2, ...b) == 6
  f(...a, 3) == 6
  f(...b, 0, ...b) == 6

> ES6 is a mess. Javascript just got harder.

Want some cheese with that whine? It got more complicated, yes. But I'm liking most of the changes, personally. A lot. Most of them are long overdue.

BTW, if you open Firefox's console, you can try out many examples. Firefox already supports tons of ES6.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: