Reputation: 93408
Can anyone explain to me the purpose of JavaScript code like this:
this._handleBlah = this._handleBlah.bind(this);
It appears in a constructor and this pattern seems to be used across a code base I'm reading.
Upvotes: 0
Views: 26
Reputation: 413826
It's useful when the "member" functions are going to be used as event handlers, or in other similar callback situations. The bound versions will have the correct this
value.
Upvotes: 2