()=>之间有什么区别? react-native javascript中的{}和function(){}? [英] What is the difference between () => {} and function() {} in react-native javascript?
问题描述
我见过一些定义为 function(){}
的函数,以及一些定义为()=>的函数。 {}
。
I have seen some functions defined as function(){}
and some functions defined as () => {}
.
这与Javascript版本ES6有关吗?
Is this related to Javascript version ES6?
此外,如何使用这个
关键字从一个函数定义更改为另一个?
Also, how does use of this
keyword change from one function definition to another?
推荐答案
()=> {}
被称为 箭头功能 。正如你所说,它们是ES6的一部分。从链接页面:
The () => {}
is called an arrow function. They are, as you said, part of ES6. From the linked page:
与函数表达式相比,箭头函数表达式具有更短的语法,并且词法绑定
this
value(不绑定自己的此
,参数
,超级
或new.target
)。箭头函数始终是匿名的。
An arrow function expression has a shorter syntax compared to function expressions and lexically binds the
this
value (does not bind its ownthis
,arguments
,super
, ornew.target
). Arrow functions are always anonymous.
这篇关于()=>之间有什么区别? react-native javascript中的{}和function(){}?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!