Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid this-bound method closure creation when using method.bind #10737

Closed
nadako opened this issue Jun 29, 2022 · 0 comments
Closed

avoid this-bound method closure creation when using method.bind #10737

nadako opened this issue Jun 29, 2022 · 0 comments

Comments

@nadako
Copy link
Member

nadako commented Jun 29, 2022

This is better illustrated with an example:

class C {
	public function new() {
		run(process.bind(42));
	}

	public function run(f:()->Void) {
		f();
	}

	public function process(value:Int) {
		trace(value);
	}
}

function main() {
	new C();
}

this will generate the following JS (although I'm pretty sure it's not js-specific, since the method closure must be created on all platforms)

let _g = $bind(this,this.process);
let value = 42;
this.run(function() {
	_g(value);
});

we have two closures here: the one comes from $bind, and the one from .bind-ing that to actual arguments. but the first one is redundant and we could instead generate

let _gthis = this;
let value = 42;
this.run(function() {
	_gthis.process(value);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant