airbnb / airbnb/javascript

Isn't section 5.1 "Use object destructuring" conflicting with 3.3 "Use object method shorthand" ?

Abierto
#3,136 11 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
148k
Forks
26.6k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Lee las secciones 3.3 y 5.1 de la guía de estilo y reproduce después el ejemplo de object-method y destructuring del issue. Revisa la discusión en los comentarios para encontrar una interpretación acordada y documenta una recomendación clara y sin conflictos, con un ejemplo que muestre cuándo se aplica la guía. El trabajo estará terminado cuando las dos secciones ya no sugieran un uso combinado inseguro.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
documentation
Tipo de issue
Documentación
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.