HaxeFoundation / HaxeFoundation/haxe

[js (and maybe others?)] improve generation of dynamic methods to avoid unnecessary `$bind`

Open
#9,598 2 comments 0 reactions 0 assignees View on GitHub
enhancement platform-javascript
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.