javascript - React-Native JavaScript 中 () => {} 和 function() {} 有什么区别?

标签 javascript react-native

我看到一些函数定义为 function(){}以及一些定义为 () => {} 的函数.

这与 Javascript 版本 ES6 有关吗?

另外,如何使用 this关键字从一个函数定义更改为另一个函数定义?

最佳答案

() => {} 称为 arrow function 。正如您所说,它们是 ES6 的一部分。从链接页面:

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.

关于javascript - React-Native JavaScript 中 () => {} 和 function() {} 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37796654/

相关文章:

javascript - 如何循环遍历 Alexa Intent 中的对象数组?

php - 显示自定义帖子类型标题的列表

react-native - 如何在 native react 中检查设备是否连接到蓝牙?

android - 在不提示的情况下 react native 读取用户电子邮件

reactjs - 在下拉列表中设置重置按钮

javascript - 如何从 ASP.NET 变量中为 JavaScript 变量提供数据?

javascript - 使用 ServiceStack 的纯 AppHost 实现提供捆绑的 JavaScript

javascript - 在数组内的对象中搜索

ios - 从 iOS 照片库 uri 获取 base64 照片

javascript - 与 react 导航的深度链接不起作用