21 }
22
23 onConnect = action => {
24 const _this = this25
26 if (action === SocketStatus.CONNECTED) {
27 _this.onSocketConnectionChange(true)
This rule prohibits assigning variables to this
.
//Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well.
//Instead of storing a reference to this and using it inside a function () {:
const self = this;
setTimeout(function () {
self.doWork();
});
// Use () => arrow lambdas, as they preserve this scope for you:
setTimeout(() => {
this.doWork();
});