rn笔记:关于const {val} 与 const val

来源:互联网 发布:阿里云网站客服 编辑:程序博客网 时间:2024/06/08 14:56

一直搞不清楚const {val} 与 const val有什么区别,今天做了一个demo才初步搞清楚

例:
const {navigation} = this.props;
const navigation = this.props.navigation

二者是等价的,只不过 {navigation}是自动从 this.props的属性中获取navigation
navigation = this.props.navigation就是指 this.props.navigation本身了

最后调用方法都是
navigation.navigate(“screen”)

说明{navigation}最终也转换成了const navigation(猜测)

本人刚学习RN不久,若以上内容有说的不对的地方,还望大手们不吝赐教!

原创粉丝点击