0

I am working with the following event handler:

eventClicked(event) {
  alert(JSON.stringify(event));
}

I am trying to figure out what is difference between using .bind(this) and not binding the this context in the above event handler.

I have tried both approaches and they both yield the same result. So, why we use .bind(this)?

iamdanchiv
  • 4,052
  • 4
  • 37
  • 42
rnn
  • 2,393
  • 3
  • 21
  • 39
  • Please read this [article](https://medium.com/@denny.headrick/this-bind-this-a-javascript-story-313ff84a12c8) – Firdous nath Mar 12 '19 at 13:43
  • 1
    Possible duplicate of [Why and when do we need to bind functions and eventHandlers in React?](https://stackoverflow.com/questions/41113798/why-and-when-do-we-need-to-bind-functions-and-eventhandlers-in-react) – iamdanchiv Mar 12 '19 at 14:49
  • bind is a javascript function that allows you to attach a this object. What that means is that if your handler is going to be called in a different context you can make sure it still uses the correct this object. – Niels Ladekarl Mar 12 '19 at 14:52

0 Answers0