I have this situation of a typescript class. This is a minimal example.
class Example {
private foo(arg: string){
console.log(arg);
}
private list = [
{
name: 'Hello'
callableFunction: function(x: string) {
this.foo(x);
}
}
]
public execute() {
this.list.forEach(listElement => {
listelement.callableFunction('Hello Foo Bar');
})
}
}
I am getting _this is not a function
The translated js code looks like
...
callableFunction: function (x) {
var _this = this;
_this.foo(x); // <-- error here
My tsconfig is fairly standard i think...
{
"compilerOptions": {
"outDir": "./build",
"allowJs": true,
"target": "es5",
"moduleResolution": "node",
"strictNullChecks": true
}
}
I know that there exist lots of posts on this topic, still I could nit find any post describing my situation with class methods.