react native onPress响应方法是否加bind(this)
2017-11-10 10:48
417 查看
最近在学习react native 但是一直不明,为啥定义一个方法,在onPress中为啥要写成this.back.bind(this),我back就是一个方法为啥还要再bind(this). 其实就是一个作用域,绑定这个作用域中的方法。
那么其实我们有两种写法去定义onPress的响应方法。
这种写法不用去bind了,
()=>{} 这种形式的代码,语法规定就是(function(){}).bind(this),即自动添加了bind this
这种要bind的
那么其实我们有两种写法去定义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的
相关文章推荐
- react 的 bind this 几种方法
- react native 触摸的响应方法以及过程(三)
- React-native 知识点-this.bind-返回键-React.cloneElement-控件显示隐藏-ScrollView
- react native 代参bind this 的两种方式
- JavaScript中call,apply,bind方法的总结(改变this指向)
- ReactNative bug:Application has not bean registered.This is either due to require()error dur
- java中抽象的(abstract)方法是否可同时是静态的(static),是否可同时是本地方法(native),是否可同时被synchronized修饰
- 轻松搞定this绑定方法 call apply bind
- 使用webstrom开发react-native时react-native代码会出现红色下划线的解决方法
- bind方法解决this作用域问题
- react-native 调用原生方法
- 《React-Native系列》17、 RN中this所引起的undefined is not an object错误
- 规避 React 组件中的 bind(this)
- react-native 滚动视图点击事件无法响应的情况
- java中抽象的(abstract)方法是否可同时是静态的(static),是否可同时是本地方法(native),是否可同时被synchronized修饰
- 关于react-native不能热加载的解决方法
- Java - 抽象的(abstract)方法是否可同时是静态的(static),是否可同时是本地方法(native),是否可同时被synchronized修饰?
- react-native--基础(方法调用)
- React Native调试方法
- eclipse,debug执行到this调用方法时,就会出现无响应的情况