Isn't section 5.1 "Use object destructuring" conflicting with 3.3 "Use object method shorthand" ?
- Lingua principale
- JavaScript
- Stelle
- 148k
- Fork
- 26.6k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
In section 5.1 it is stated the following:
> Use object destructuring when accessing and using multiple properties of an object.
In section 3.3, it is stated the following:
> Use object method shorthand.
Let's look at the following example:
```js
const foo = {
bar: 5,
// applying 3.3
computeSomething() {
return this.bar + 5;
}
};
// applying 5.1
const {bar, computeSomething} = foo;
console.log(bar);
computeSomething();
```
The last instruction throws the following error:
> TypeError: Cannot read properties of undefined (reading 'bar')
So, applying both 3.3 and 5.1 can lead to an incorrect code. Either we have to use arrow functions in objects definition; or we have to not use destructuring; but both 3.3 and 5.1 can't be recommended together without creating potential issues. At least, that's what I'm feeling.
What do you think? Did I miss the point or a clarification in the specs about that?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Leggi le sezioni 3.3 e 5.1 della guida di stile, quindi riproduci l’esempio di object-method e destructuring dell’issue. Controlla la discussione nei commenti per individuare un’interpretazione condivisa e documenta una raccomandazione chiara e non in conflitto, con un esempio che mostri quando si applica la guida. Il lavoro è completato quando le due sezioni non suggeriscono più un uso combinato non sicuro.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100