News for hackers. Stuff that matters.
Re:JavaScript fundamentals before learning React by tills13 on Friday July 20, 2018 @12:23AM (#17572438)
isn't that functionally equivalent to `onClick={ this.smth }`?
Re:JavaScript fundamentals before learning React by barskern on Friday July 20, 2018 @01:30AM (#17572705)
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.
Re:JavaScript fundamentals before learning React by wongma on Friday July 20, 2018 @01:51AM (#17572797)
no, because you're not passing the arg in now right?
Re:JavaScript fundamentals before learning React by williamdclt on Friday July 20, 2018 @06:33AM (#17573843)
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).