Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取绑定的属性。该属性未在react中定义_Javascript_Reactjs - Fatal编程技术网

Javascript 无法读取绑定的属性。该属性未在react中定义

Javascript 无法读取绑定的属性。该属性未在react中定义,javascript,reactjs,Javascript,Reactjs,如果jsx中有bind(this),那么在构造函数中使用bind是可选的,对吗 render(){ return( <input onChange={this.myFunc.bind(this)} type="text"/> ) } myFunc(){ alert('should trigger'); } render(){ 返回( ) } myFunc(){ 警报(“应触发”); } 但是我得到了无法读取bind属性的错误。这是我的完整js文件

如果jsx中有bind(this),那么在构造函数中使用bind是可选的,对吗

render(){
   return(
      <input onChange={this.myFunc.bind(this)} type="text"/>
   )
}

myFunc(){
    alert('should trigger');
}
render(){
返回(
)
}
myFunc(){
警报(“应触发”);
}
但是我得到了无法读取bind属性的错误。这是我的完整js文件


而不是:

  <input onChange={myFunc.bind(this)} type="text"/>


而不是:

  <input onChange={myFunc.bind(this)} type="text"/>

Abdennour在技术上是正确的,但是每次调用.render()时绑定同一个方法的效率低于在构造函数中绑定一次的效率。许多开发人员认为这种方法是最好的实践:

class MyComponent extends React.Component {
    constructor() {
        super();

        this.myFunc = this.myFunc.bind(this);
    }

    myFunc(){
        alert('should trigger');
    }

    render() {
        return(
            <input onChange={this.myFunc} type="text"/>
        );
    }
}
类MyComponent扩展了React.Component{ 构造函数(){ 超级(); this.myFunc=this.myFunc.bind(this); } myFunc(){ 警报(“应触发”); } render(){ 返回( ); } }
Abdennour在技术上是正确的,但是每次调用.render()时绑定同一个方法的效率低于在构造函数中绑定一次的效率。许多开发人员认为这种方法是最好的实践:

class MyComponent extends React.Component {
    constructor() {
        super();

        this.myFunc = this.myFunc.bind(this);
    }

    myFunc(){
        alert('should trigger');
    }

    render() {
        return(
            <input onChange={this.myFunc} type="text"/>
        );
    }
}
类MyComponent扩展了React.Component{ 构造函数(){ 超级(); this.myFunc=this.myFunc.bind(this); } myFunc(){ 警报(“应触发”); } render(){ 返回( ); } }
Do
this.myFunc.bind(this)
您的Pastebin链接不起作用。请在此处发布所有相关代码,不要在其他网站上发布。请执行
this.myFunc.bind(this)
您的Pastebin链接不起作用。请在这里发布所有相关代码,不要在其他网站上发布。我在文件中发布了这些代码,但仍然有错误。我在文件中发布了这些代码,但仍然有错误。