Your IIFE creates a new area. thisthen refers to the IIFE region, where this.foois undefined.
How you get around this binds your IIFE.
class Foo {
constructor() {
this.foo = 'foo';
}
sayHi() {
return (() => {
return this.foo;
}.bind(this))();
}
}
let f = new Foo();
console.log(f.sayHi());
source
share