All "soft-bind" proposals I have heard have failed to get traction for two reasons:

1. Binding |this| makes an abstraction with its own integrity. Overriding the |this| binding only some of the time violates that abstraction.

2. Implementations including beloved V8 and venerable SpiderMonkey would have to recompile target soft-bound functions, or else provide an extra parameter to replace what is for =>a lexical up-var reference. And extra parameters and/or recompilation steps cost performance and code complexity, always.

Whatever you think of (1) -- hey, sometimes abstractions need to be broken (I'm not being sarcastic in general, but for => I disagree with this aside) -- (2) is a big problem. If V8 and SpiderMonkey won't go for "soft-bind", there's no hope.

/be

Yehuda Katz wrote:
I've been thinking a lot about the proposed arrows and its affect on `this`.

To start, I'm a worried that `call` and `apply` don't "work" on arrow function. This is of course the correct behavior for jQuery-like use-cases, but the proposed semantics interfere with more intentional uses of `call` and `apply`.

I'd like to propose the following:

* `call` and `apply` modify `this` in an arrow function
* `softCall` and `softApply` do not modify `this` in arrow functions, but do modify `this` in regular functions

This would allow libraries like jQuery to continue providing advisory `this` bindings without interfering with intentional modifications to the `this` binding. (jQuery could do `softCall = Function.prototype.softCall || Function.prototype.call` to quickly "polyfill").

I'm not sure if this makes sense, but something about breaking `call` and `apply` doesn't sit right with me.

Thoughs?

Yehuda Katz
(ph) 718.877.1325
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to