1

I wander if it's possible to use arrow function with generators like this:

app.use( *() => {
    ...body of function
});

Thanks!

Carnaru Valentin
  • 1,503
  • 14
  • 23
  • 2
    Did you try running it ? – Serge K. Jul 21 '17 at 07:58
  • Ok, you're ironic... and how should syntax looks like? – Carnaru Valentin Jul 21 '17 at 08:09
  • Yes I am, you're basically asking if you can run the code you wrote, go ahead, try it yourself and see what happens ! Then, when you'll see it doesn't work, either do your own searches, or look at @hsz 's answer. – Serge K. Jul 21 '17 at 08:14
  • 1
    If needed, you can easily omit generator function name to achieve anonymous function, like `app.use(function*() { /* body of generator */ })`. More discuss here: https://stackoverflow.com/a/34108006/7878274 – Vladislav Ihost Jul 21 '17 at 08:15
  • Yes, but for arrows function maybe works like `*() => {}" or "()* => {}` and so on.. You see? It's difference to be smart and think you're smart... – Carnaru Valentin Jul 21 '17 at 08:16

1 Answers1

3

No, it's not possible to make it shorter than described in the documentation:

function* name([param[, param[, ... param]]]) {
   statements
}

Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*

Kaiido
  • 103,356
  • 8
  • 183
  • 231
hsz
  • 143,040
  • 58
  • 252
  • 308