()=>之间有什么区别? react-native javascript中的{}和function(){}? [英] What is the difference between () => {} and function() {} in react-native javascript?

查看:132
本文介绍了()=>之间有什么区别? react-native javascript中的{}和function(){}?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过一些定义为 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 own this, arguments, super, or new.target). Arrow functions are always anonymous.

这篇关于()=>之间有什么区别? react-native javascript中的{}和function(){}?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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