javascript-tutorial / javascript-tutorial/en.javascript.info
Incorrect information of Data Types/Array Methods about thisArg
Personne n'a encore pris cette issue.
- Langage dominant
- HTML
- Étoiles
- 25.5k
- Forks
- 4k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par l’article Data Types/Array Methods et repérez l’exemple de thisArg présenté dans l’issue. Vérifiez l’explication par rapport au comportement de l’exemple, puis mettez à jour la formulation pour expliquer correctement le problème et évaluez si une section plus générale sur this est nécessaire. C’est terminé lorsque l’article n’attribue plus l’erreur à la mauvaise cause.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- documentation
- Type d'issue
- Documentation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100