javascript-tutorial / javascript-tutorial/en.javascript.info
Incorrect information of Data Types/Array Methods about thisArg
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- HTML
- Estrellas
- 25.5k
- Forks
- 4k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
I was reading the article on Data Types, Array Methods when I saw the example code for thisArg. The example code below:

The explanation why the code would give a problem if we omit the thisArg argument here is:
>If in the example above we used users.filter(army.canJoin), then army.canJoin would be called as a standalone function, with this=undefined, thus leading to an instant error.
The canJoin isn't called as a standalone function. It's been called in the context of army with the dot syntax. Inside canJoin where we use the 'this' keyword, 'this' points correctly to army. The problem here for some reason is the (implicit in that case as we haven't define it) is the user member of the users array. That's what causes the error and not the omission of the thisArg.
I believe that a whole section about how 'this' works would be highly valuable as it's extremely important to know and often a source of bugs.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el artículo Data Types/Array Methods y localiza el ejemplo de thisArg mostrado en el issue. Revisa la explicación comparándola con el comportamiento del ejemplo; después, actualiza la redacción para explicar correctamente el problema y evalúa si es necesaria una sección más amplia sobre this. La tarea estará terminada cuando el artículo ya no atribuya el error a la causa equivocada.
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
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100