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

Incorrect information of Data Types/Array Methods about thisArg

未关闭
#3,766 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
HTML
星标
25.5k
派生
4k
PR 合并指标
30 天内没有已合并 PR

描述

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.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Data Types/Array Methods 文章开始,找到 issue 中展示的 thisArg 示例。根据示例的行为检查说明,然后更新措辞以准确解释问题,并评估是否需要增加一个关于 this 的更广泛章节。当文章不再将错误归因于错误的原因时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
documentation
Issue 类型
文档
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。