class Example{
static foo():string{
return this.bar();
}
static bar():string{
return "bar";
}
}
class Broken{
static breaksThis(callback: () => string):string{
return callback();
}
}
console.log(Example.foo()); // works
console.log(Broken.breaksThis(Example.foo)); // Error at line 3: "this is undefined"
An interactive Example can be found here.
I would like to understand why the first log works as intended but the second fails. And how could I fix it?