Closed neophob closed 4 years ago
Hmm, does removing .bind()
in the helper keep the scope to this
?
nop, just tried, played around with this but did not have a good solution either atm.
a VERY ugly fix would be:
let self: VpmController;
...
constructor(player: Player) {
...
self = this;
}
public Run() {
logger().debug('RUN', self.gameName, new Error('x').stack);
}
After reading https://www.freecodecamp.org/news/this-is-why-we-need-to-bind-event-handlers-in-class-components-in-react-f7ea1a6f93eb/ I propose this solution:
for each function which is NOT a get/set function, use this in the constructor:
constructor(player: Player) {
...
this.Run = this.Run.bind(this);
}
any objections?
Can be closed now, right?
vpm-controller.ts (class) exposes this function:
when this class is called,
this
is assigned to the function instead to the class. Bcktrace of this call:this is definitive correct for setter and getter calls, not sure if thats the case for all class methods.
Proposal to solve this: