javascript-tutorial / javascript-tutorial/en.javascript.info

Incorrect information of Data Types/Array Methods about thisArg

Open
#3,766 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
25.5k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

I was reading the article on Data Types, Array Methods when I saw the example code for thisArg. The example code below:
![Example code](https://github.com/user-attachments/assets/de6aabf7-a7d9-40d1-a473-e8dffd849c40)

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Data Types/Array Methods article and locate the thisArg example shown in the issue. Review the explanation against the example's behavior, then update the wording to accurately explain the problem and assess whether a broader section on this is needed. Done means the article no longer attributes the error to the wrong cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.