HaxeFoundation / HaxeFoundation/haxe
[js (and maybe others?)] improve generation of dynamic methods to avoid unnecessary `$bind`
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
> For some context, see https://github.com/haxetink/tink_core/pull/133
```haxe
class C {
dynamic function func() {}
function run() {
haxe.Timer.delay(func, 15);
}
}
```
This will currently generate:
```js
class C {
func() {
}
run() {
haxe_Timer.delay($bind(this,this.func),15);
}
}
```
The `$bind` there only makes sense for the default implementation (because that's the only place it's possible to access `this`), and given that `dynamic` methods are usually made to be overwritten anyway, the `$bind`ing becomes useless, so we could save some ticks by avoiding it.
What we could do instead of generate `this.func = $bind(this, this.func);` in the constructor to bind the default implementation and never bind when accessing dynamic methods as callbacks.
Contributor guide
Assessment
This issue has not been assessed yet.