3 ms·
isn't that functionally equivalent to `onClick={ this.smth }`?
by tills13 8y ago
isn't that functionally equivalent to `onClick={ this.smth }`?
- barskern 8y agoNo it is not equal because the former autobinds `this` into the body of the arrow function, however the latter is "just" a function pointer hence will not be called with the correct `this` value. One way to get around this is using `this.smth.bind(this)`, which binds the correct `this` for the later execution.
- wongma 8y agono, because you're not passing the arg in now right?
- williamdclt 8y agoOf course you are. The `smth` method will receive whatever arguments the caller gives. This totally works but only if `smth` has been declared as an arrow function (so that is captures the class `this` context).