Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect information of Data Types/Array Methods about thisArg #3766

Open
anastasiosPou opened this issue Oct 4, 2024 · 0 comments
Open

Comments

@anastasiosPou
Copy link

I was reading the article on Data Types, Array Methods when I saw the example code for thisArg. The example code below:
Example code

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.

@anastasiosPou anastasiosPou changed the title (Maybe) Incorrect information of Data Types/Array Methods about thisArg Incorrect information of Data Types/Array Methods about thisArg Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant