I am passing a class method as a parameter to a new class instantiation like this:
class Abc {
constructor() {
this.a = () => { };
}
b = new Def(this.a);
}
I get 'cannot read property a of undefined' in browser console. Why is a
undefined
inside b = new Def(this.a)
? On debugging, I found that browser throws the error and the constructor code is never reached. Why is this happening?
Note: I am using babel, so I can use class fields and hence b = new Def()
is a valid syntax here.