react native onPress响应方法是否加bind(this)
来源:互联网 发布:png格式打开软件 编辑:程序博客网 时间:2024/05/21 17:34
最近在学习react native 但是一直不明,为啥定义一个方法,在onPress中为啥要写成this.back.bind(this),我back就是一个方法为啥还要再bind(this). 其实就是一个作用域,绑定这个作用域中的方法。
那么其实我们有两种写法去定义onPress的响应方法。
1.不加bind(this)
onPress={this.back}.... back = () => { const {navigator} = this.props; navigator.pop(); }
这种写法不用去bind了,
()=>{} 这种形式的代码,语法规定就是(function(){}).bind(this),即自动添加了bind this
2.需要加bind
onPress={this.back.bind(this)}.... back() { const {navigator} = this.props; navigator.pop(); }
这种要bind的
阅读全文
0 0
- react native onPress响应方法是否加bind(this)
- react-native react 中的bind(this)
- 【React Native】React Native的bind方法
- react 的 bind this 几种方法
- React Native Touchable(按钮) onPress 事件系列总结
- react native 代参bind this 的两种方式
- react native 代参bind this 的两种方式
- React Native学习笔记之--在LisvView的cell中调用TouchableOpacity的onPress方法时报错
- react系列-bind this
- React的bind(this)
- React-native 知识点-this.bind-返回键-React.cloneElement-控件显示隐藏-ScrollView
- react-native当点击TouchableOpacity时,要点击两下才会触发onPress解决办法
- react native 触摸的响应方法以及过程(一)
- react native 触摸的响应方法以及过程(二)
- react native 触摸的响应方法以及过程(三)
- React Native 中Image 加本地图片的方法
- React Native 手势响应系统
- react native -- this.props.children
- org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Document contains multiple val
- Linux内核分析
- 2017.11.8. Floyed求最小环
- 关于De-pCode在线工具失效的问题
- Linux命令行总结
- react native onPress响应方法是否加bind(this)
- js中怎样获取当前的时间戳
- Spring--《Spring实战》第6章ValidationMessages.properties使用问题
- iOS 用代码修改图片颜色
- SSM学生管理系统SpringMVC+MyBatis
- Jlink接口的Jtag和SWD接口定义
- AngularJS 学习历程一
- Leetcode 139
- WindowCE 下 Qt Library生成及使用