Open
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:
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?
Metadata
Metadata
Assignees
Labels
No labels