-4

I just came across this code:

routes: routes.map(route => ({

Notice the arrow function being followed by a closure. Why are closures used here?

see this repo for reference: https://github.com/prograhammer/vue-pizza/blob/master/src/http/router.js#L33

Bunker
  • 1,040
  • 3
  • 12
  • 25
  • 4
    that's not a closure. It's just the start of an object literal. The arrow function returns the object. – Pointy Sep 19 '18 at 20:58
  • It is impossible to tell whether a function is a closure or not without seeing both the body of the function and the surrounding context. Also, what do you mean by "the arrow function followed by a closure"? You don't even show the arrow function, let alone what follows the arrow function, so how can we tell you something about what follows it? – Jörg W Mittag Sep 19 '18 at 21:00
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions – epascarello Sep 19 '18 at 21:00

1 Answers1

1

It returns an object. The parenthesis is to denote that this is an object not a block.

() => {return {hello: 'world' } } === () => ({hello: 'world'})

hasanain
  • 764
  • 5
  • 12