Hacker News new | ask | show | jobs
by tills13 2897 days ago
isn't that functionally equivalent to `onClick={ this.smth }`?
2 comments

No 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.
no, because you're not passing the arg in now right?
Of 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).