Isn't section 5.1 "Use object destructuring" conflicting with 3.3 "Use object method shorthand" ?
- Vorherrschende Sprache
- JavaScript
- Sterne
- 148k
- Forks
- 26.6k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Lies die Abschnitte 3.3 und 5.1 des Styleguides und reproduziere dann das Beispiel zu object-method und Destructuring aus dem Issue. Prüfe die Kommentardiskussion auf eine vereinbarte Interpretation und dokumentiere eine klare, widerspruchsfreie Empfehlung mit einem Beispiel, das zeigt, wann die Richtlinie gilt. Erledigt ist die Aufgabe, wenn die beiden Abschnitte nicht mehr zu einer unsicheren kombinierten Verwendung raten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100