javascript-tutorial / javascript-tutorial/en.javascript.info
The arrow function.... The lookup of this is made exactly the same way as a regular variable search: in the outer lexical environment.
还没有人认领这个 Issue。
- 主要语言
- HTML
- 星标
- 25.5k
- 派生
- 4k
- PR 合并指标
- 30 天内没有已合并 PR
描述
I have tried to test this, i believe arrow function doesn't look up for 'this', in the outer lexical environment, it remembers the 'this' of the place where it is defined.
In the below code: arrow function is passed to another function and that function calls the arrow function at line //**. At line //** 'this' is 'window', so if arrow function looks up for this in outer lexical environment, then 'this' should be window object, not cl_Test.
Hence, i believe the statement put by you in arrow functions revisited should be changed. Please correct me if i am wrong.
function cl_Test() {
// let name = 'Pradeep';
this.name = 'Pradeep';
this.age = '31';
this.arrowF = () => {
console.log(`${this.name + ' ' + this.age}`);
};
this.normalF = function () {
console.log(name)
};
this.arrowF2 = () => {
console.log(name);
}
};
function fTest(f1) {
f1(); // **
};
let o1 = new cl_Test();
o1.name = 'Sunil';
o1.age = '34';
fTest(o1.arrowF); //*
fTest(o1.normalF);
fTest(o1.arrowF2);
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
Start by reading the “arrow functions revisited” section referenced in the issue and compare its statement about how arrow functions obtain this with the supplied example. Verify the behavior of arrowF and normalF when passed to fTest, then update the explanation so it accurately describes lexical this.】【。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100