Isn't section 5.1 "Use object destructuring" conflicting with 3.3 "Use object method shorthand" ?
- Dominant language
- JavaScript
- Stars
- 148k
- Forks
- 26.6k
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Read sections 3.3 and 5.1 of the style guide, then reproduce the object-method and destructuring example from the issue. Check the comment discussion for an agreed interpretation and document a clear, non-conflicting recommendation, with an example showing when the guidance applies. Done means the two sections no longer suggest unsafe combined usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100