a New Reagire classi ES6 this
ha bisogno di essere rilegata come indicato qui: http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding per esempio:Perché vincolante è necessario in ES6 reagiscono classi
class Counter extends React.Component {
constructor() {
super();
this.tick = this.tick.bind(this);
}
tick() {
...
}
...
}
La spiegazione di questo è perché è il comportamento di default, se faccio una classe ES6 e poi faccio una nuova istanza di esso this
verrà rilegato
import React from 'React'
class Test extends React.Component {
constructor() {
super()
}
foo() {
console.log('bar')
}
hello() {
this.foo()
}
}
var test = new Test()
test.hello()
// > bar
Perché è necessario obbligatorio in Reagire, allora?