zoukankan      html  css  js  c++  java
  • ReactNative踩坑日志——函数绑定this

        ES6语法定义的函数没有自动绑定this,所以在函数中使用了 this.xxx 就会报错,因为没有把类实例等this传进函数中。

        有两种方法绑定this:

        法1:在构造函数中为其他函数绑定this

    construtor(props){
       super(props);
       ......
       this.funcName = this.funcName.bind(this)//2:为函数绑定this
    }
    //1:自定义函数
    funcName(args){
    
    }

        法2:用箭头函数自定义函数,自动绑定this

    funcName= (args)=>{ //定义箭头函数,赋值给函数名,自动绑定this
    
    }
  • 相关阅读:
    搜索框的创建
    自定义非等高 Cell
    自定义等高 Cell
    表格多选删除
    聊天布局
    表格编辑
    表格折叠
    tableView 的协议方法
    UITouch
    UIDevice
  • 原文地址:https://www.cnblogs.com/ygj0930/p/7488064.html
Copyright © 2011-2022 走看看