I'm messing with AST and what I need (in a nutshell) is this:
(new Test().containsProperty ? new Test().anotherMethod : new Test().method)()
But it gives me Uncaught TypeError: Cannot read property '...' of undefined
, because for some reason it treats this
wanted in the method
as undefined
. Why?
class Test {
constructor() {
this.property = 'Test';
}
method() {
alert(this.property);
}
}
try {
// Doesn't works
(new Test().containsProperty ? new Test().anotherMethod : new Test().method)();
// Either
// (undefined || new Test().method)();
// But this does
// (new Test().method)();
} catch(error) {
alert(error);
}