为什么隐式args调用在显式执行时不起作用?

时间:2018-10-05 19:45:28

标签: javascript typescript

考虑以下内容,隐式参数调用就像静态调用一样,初始化属性变为未定义。

这是预期的吗?如果是,为什么?

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
  }
}

0 个答案:

没有答案