felixge / felixge/node-style-guide

Ternary operators, again

Aperta
#89 2 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
5k
Fork
893
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I agree that multi-line ternary operators make sense. However, the following is (as far as I know) bad, due to ASI:

```
var foo = (a === b)
? 1
: 2;
```

JShint will throw an error on this code, saying “Bad line breaking before '?'”.

If you insist on using multi-line ternary operators, you might prefer the following style:

```
var foo = (a === b) ?
1 :
2;
```

I agree that it is less readable, because the question mark and the colon are more obvious at the beginning of the line. But I wouldn’t want to mess with ASI and depend on implicit fixes of the JS engine, either.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.