See the example below. Inside of a callback A.handleEvent, I was expecting "this" to be an instance of A instead of B, even though it is being called from B.
class A {
constructor() {
this.text = 'A';
this.b = new B(this);
}
handleEvent = () => {
console.log(this.text); // outputs 'B' instead of 'A'
}
}
class B {
constructor(a) {
this.text = 'B';
this.a = a;
setTimeout(() => {
this.handleEvent();
}, 1000);
}
handleEvent = () => {
this.a.handleEvent();
}
}