考虑以下内容,隐式参数调用就像静态调用一样,初始化属性变为未定义。
这是预期的吗?如果是,为什么?
export class MyClass {
private prop: string;
constructor(){
this.prop = 'value!';
}
foo(){
// This works
something.subscribe((x: string) => this.bar(x));
// This doesn't
something.subscribe(this.bar);
//...
}
bar(z: string) {
console.info(this.prop);
// Is undefined with second call
}
}