I am writing a function in React JSX which contains callbacks that need to talk to this
this.socket.on('addWashedMission', washedMission => {
console.log('onAddWashedMission - %s - %s', washedMission.name,
new Date(washedMission.birthtime));
this.state.washedMissions.filter(function(o) {
return o.name === washedMission.name;
}).forEach(function(element, i, arr) {
// HERE IT IS //
this.state.washedMissions.state.washedMissions.slice(
this.state.washedMissions.state.washedMissions.indexOf(element), 1);
});
this.state.washedMissions.push(washedMission);
this.state.washedMissions.sort(function(a,b) {
return b.birthtime - a.birthtime;
});
this.setState({
washedMissions: this.state.washedMissions
});
});
Notice the this.state.washedMissions
? When I am inside that callback, the Firefox script debugger shows me that the browser doesn't know what this
is and thus I can't manipulate my arrays this way.
How can I ensure that this
is within the scope of my callback -- and note, the callback is synchronous, so I am not worried about any timing stuff.