我很惊讶这个不起作用。(我正在运行带有 --harmony_arrow_functions
标志的 iojs
2.3.0 版本。)
class Foo {
constructor() { this.foo = "foo"; }
sayHi() { return (() => this.foo)(); }
}
f = new Foo();
f.sayHi // Cannot read property 'foo' of undefined.
我本以为箭头函数会正确获取this
的值。我有什么遗漏吗?