javascript-tutorial / javascript-tutorial/en.javascript.info
Incorrect information of Data Types/Array Methods about thisArg
- Vorherrschende Sprache
- HTML
- Sterne
- 25.5k
- Forks
- 4k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne mit dem Artikel Data Types/Array Methods und finde das im Issue gezeigte thisArg-Beispiel. Überprüfe die Erklärung anhand des Verhaltens des Beispiels, aktualisiere dann die Formulierung, um das Problem korrekt zu erklären, und beurteile, ob ein breiterer Abschnitt zu this erforderlich ist. Erledigt ist die Aufgabe, wenn der Artikel den Fehler nicht mehr der falschen Ursache zuschreibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100