`idx` should be implemented such that function calls don't lose their `this` binding
Closed this issue · 2 comments
steveluscher commented
This doesn't work:
componentWillUnmount(): void {
idx(this.foo, _ => _.bar());
delete this.foo;
}
It gets transformed to this:
(_ref = this.foo) != null
? (_ref = _ref.bar) != null
? _ref()
: _ref
: _ref;
delete this.foo;
And can throw this kind of error because internal to foo, this
is undefined
:
TypeError: Cannot read property '_baz' of undefined
This works fine:
componentWillUnmount(): void {
if (this.foo) {
this.foo.bar();
}
delete this.foo;
}
I suppose idx
should do this instead?
(_ref = this.foo) != null
? _ref.bar != null
? _ref.bar()
: _ref.bar
: _ref;
Minimal test case: (link)
steveluscher commented
yungsters commented
Obsoleted in 2.0.0.