I started to learn es6 , I write on ReactJs . I meet in event handlers methods like:

 onChange={this.selectKey.bind(this)} 

How, for example, in this tutorial Tell me please what is used for .bind(this) ?

Reported as a duplicate at Grundy. javascript 8 Jun '17 at 8:34 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    2 answers 2

    Bind is needed to hard set what this will indicate when calling a function

      You can also find this option:

       class App extends Component { constructor(props) { super(props); this.selectKey = this.selectKey.bind(this); } render() { return ( <div className="someClass"> <input onChange={this.selectKey}/> </div> ); } } 

      In fact, this is the same as your version, with the only difference that you don’t have to write .bind (this) wherever you need to call a function.