gpt4 book ai didi

react-native - React Native新手问题 '() =>'是什么意思?

转载 作者:行者123 更新时间:2023-12-02 09:26:15 24 4
gpt4 key购买 nike

这是什么意思?为什么我在文档中看到它使用的东西,但在实践中通过教程我却从未看到过?

示例:

AppRegistry.registerComponent('MyApp', () => SimpleList);

这只是一种新的表达方式吗:

function() { return SimpleList }:

即:

AppRegistry.registerComponent('MyApp', function() { return SimpleList });

最佳答案

是的,你说得对。

() => SimpleList 可以替代 function() { return SimpleList }

不,你并不是100%正确。
this 与箭头函数内的调用者相同,如果您使用 function() {}

,则不是新的 this(new context)

看看这个 (http://es6-features.org/#Lexicalthis了解更多:)

关于react-native - React Native新手问题 '() =>'是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37825126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com