w Nowym React ES6 klas this
należy zbindowanych jak podano tutaj: http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding dla npDlaczego wiązania jest potrzebne w ES6 reagować klas
class Counter extends React.Component {
constructor() {
super();
this.tick = this.tick.bind(this);
}
tick() {
...
}
...
}
Wyjaśnieniem tego jest fakt, że jest to zachowanie domyślne, jednak jeśli robię klasy ES6 a potem zrobić nowa instancja tego this
będą zbindowanych
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
wiązania Dlaczego jest potrzebny w reagują wtedy?