美文网首页
_this2 xxx is not a function

_this2 xxx is not a function

作者: WhyLingLei | 来源:发表于2018-08-07 15:20 被阅读0次

_this2 xxx is not a function

原因是,在重写
renderRow={this.renderRow}
方法的时候,这里的this不再是最外层的this,应该改成以下的形式,
错误即可解决
renderRow={this.renderRow.bind(this)}

什么是this对象

每一个函数在调用的时候都会自己主动获取两个特殊变量:this和arguments对象。

this值详细是指哪个对象是和该函数的运行环境相关的。假设是作为对象的方法,那么this就是对象实例本身;假设是一个全局函数,那么this就是window对象。用一句话来概括,this就是调用这种方法的对象。

bind方法

bind方法生成了一个新的函数,称为绑定函数,传入bind方法的第一个參数作为这个绑定函数的this对象,传入bind的第二个參数连同后面调用绑定函数时传入的參数依照先后顺序(传入bind的在前)构成绑定函数的參数。

.bind()创建了一个函数,当这个函数在被调用的时候。它的 this 关键词会被设置成被传入的值(这里指调用bind()时传入的參数)

相关文章

  • _this2 xxx is not a function

    _this2 xxx is not a function 原因是,在重写renderRow={this.rende...

  • Promise xxx is not a function

    刚刚在微信小程序开始用Promise,一直报错'handleResult is not a function' 查...

  • jq 定时器

    function del() { $('xxx').eq(0).trigger('click'); $('xxx'...

  • DOM事件模型

    DOM leave 0: xxx.onclick = function(){ ... } onclick="xxx...

  • 2022-10-24 this

    function 函数名(){} //定义函数名() //执行xxx。函数名() //等价执行,xxx就是...

  • DOM事件模型

    onclick和addEventListener('click', function() {}) xxx.oncl...

  • markdown常用

    上标 xxx 下标 xxx

  • implicit declaration of function

    (1)implicit declaration of function 'xxx' is invalid inC9...

  • js "is not a function at HT

    xxx is not a function at HTMLInputElement.onclick这样的问题,竟然...

  • this2

    根据优先级来判断函数在某个调用位置应用的是哪条规则。可以按照下面的顺序来进行判断: 函数是否在 new 中调用(n...

网友评论

      本文标题:_this2 xxx is not a function

      本文链接:https://www.haomeiwen.com/subject/ebcavftx.html