0

I'm not sure what this is called in Javascript:

exports.withLocalCallback = () => {
  return [1, 2, 3].map(x => x + 1)
}

I haven't seen this before and I can't even think of a way to google it. Can someone explain what's happening here?

pguardiario
  • 53,827
  • 19
  • 119
  • 159

1 Answers1

1

It's arrow functions, and they work almost the same as normal js functions, with the difference that 'this' is bound to the scope in which the function is defined. So you don't need to bind functions to access the correct object.

The difference is none if you don't need 'this', except is another syntax, which looks more like functional language functions.

William
  • 741
  • 4
  • 9
  • OK, so that's called arrow functions. So what's going on with the argument to map() – pguardiario Sep 01 '17 at 07:37
  • You don't need the parentheses around the arguments, or the brackets around the function. If you do that type of one-line function, the function will also return the result implicitly. So that map() functions can get a bit neater like above. – William Sep 01 '17 at 08:02
  • I found [babel](https://babeljs.io/repl/) today, this is very helpful for me to understand the new ES syntax – pguardiario Sep 02 '17 at 00:02