proposal-bind-operator icon indicating copy to clipboard operation
proposal-bind-operator copied to clipboard

This proposal sounds as in-language replacement of (0, expr) hacky syntax?

Open koteisaev opened this issue 4 years ago • 1 comments

Hello! Lately I was intrigued with the need to use syntax like (0, expr) for imports from modules to make sure it does not called on module import as this. So, what exactly happen if this proposal will be adopted, and following construct will be applied:

(undefined::module1.importedFunc)("a", true, 1, ...[1,2,3]);

What if this proposal can be extended to either

module1:>importFunc("a", true, 1, ...[1,2,3]);

or

module1->importFunc("a", true, 1, ...[1,2,3]);

to explicitly say "I want to call importFunc as independent function without relation to module1 import reference", with undefined this?

May be, :> can be used to call member method with undefined this and -> to call some method with left operand of this, like

module1:>importedFunc("a", true, 1, ...[1,2,3]);
//call `importedFunc` with `this` set to `window`
window->module1.importedFunc("a", true, 1, ...[1,2,3]);
//here call `module1.libFactory` first decoupled from `module1` import
window->(module1:>libFactory().importedFunc)("a", true, 1, ...[1,2,3]);

Thanks for reading this.

koteisaev avatar Dec 10 '21 16:12 koteisaev

That seems like a different proposal, and I’m very skeptical that there’s a use case for it outside of transpiler output, since in actual user code, this is done by destructuring the function in one statement, and calling it in the next.

ljharb avatar Dec 10 '21 19:12 ljharb