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

Incorrect information of Data Types/Array Methods about thisArg

Aberta
#3,766 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
HTML
Estrelas
25.5k
Forks
4k
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece pelo artigo Data Types/Array Methods e localize o exemplo de thisArg mostrado na issue. Revise a explicação comparando-a com o comportamento do exemplo; em seguida, atualize a redação para explicar o problema com precisão e avalie se é necessária uma seção mais ampla sobre this. O trabalho estará concluído quando o artigo não atribuir mais o erro à causa errada.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
javascript
Domínio
documentation
Tipo de issue
Documentação
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.