I'm testing classes in ES6 using traceur but it's not working as I expected.
I am trying to use a method as a reference in another class but when it's called I get the reference of the caller class when read the value of this
.
Here is my code:
class A {
constructor(anotherMethod){
this.anotherMethod = anotherMethod;
this.name = "A";
}
myMethod (){
console.log(this.name);
this.anotherMethod();
}
}
class B {
constructor(){
this.a = new A(this.myMethod);
this.name = "B";
}
myMethod(){
console.log(this.name);
}
}
var c = new B();
c.a.myMethod();
My expected log is:
A
B
But it is showing:
A
A