什么是词汇“这”? [英] What is lexical 'this'?

查看:122
本文介绍了什么是词汇“这”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个箭头函数表达式(也称为胖箭头函数)可以让某人简单介绍一下这个词汇?


与函数表达式相比语法更短,并且对该值进行词法绑定(不绑定其自身的this,arguments,super或new.target)。箭头函数始终是匿名的。




这是否意味着当我使用'Fat Arrow'功能的'this'ref调用函数成员时,'this'总是指包含this?

解决方案

你似乎正确理解了这个在箭头功能。我会提供一个解释,我认为增加了对话,希望巩固你的理解。



你可能知道,当你定义一个函数并在其中使用一个变量,它检查变量是否已在其范围内定义。如果是,它使用它!如果没有,它将检查该变量定义的封闭范围。它会检查封闭的范围,直到找到变量或达到全局范围。现在, arrow函数的函数定义隐式定义了这个。因此,当您尝试在其范围内使用 时(因为它们在自己的范围内找到它们),它们将永远不会检查封闭的范围。箭头函数不定义自己的这个,所以他们去附近的范围,寻找它,就像你试图在其范围内使用的任何变量一样。


Could someone please give me a brief introduction to lexical this?

"An arrow function expression (also known as fat arrow function) has a shorter syntax compared to function expressions and lexically binds the this value (does not bind its own this, arguments, super, or new.target). Arrow functions are always anonymous."

Does it mean that when I call a function member using the 'this' ref from a 'Fat Arrow' Function the 'this' always refers to the enclosing 'this'?

解决方案

You seem to have the correct understanding of what happens with this in an arrow function. I will offer an explanation that I think adds to the conversation and hopefully solidifies your understanding.

As you probably know, when you define a function and use a variable inside of it, it checks if the variable has been defined in its scope. If it is, it uses it! If not, it checks the enclosing scope for that variable definition. It keeps checking enclosing scopes until it finds the variable or reaches global scope. Now, function definitions that are not arrow functions define this for you, implicitly. Thus, they will never check an enclosing scope when you try to use this in their scope (because they find it in their own scope!). Arrow functions do NOT define their own this, so they go to the enclosing scope and look for it just as they would with any variable you try to use in their scope.

这篇关于什么是词汇“这”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆