Binding arrow functions.

Mark Everitt mark.s.everitt at gmail.com
Mon Aug 25 03:23:23 PDT 2014


I got my lack-of-sleep addled head around this by realising that an arrow
function performs like an immediately bound function expression:

```js
var test = (function (){
    // Do stuff with this...
}).bind(this);
```

i.e. Domenic's second example function. Then it was obvious that arrow
functions are not really throwing anything new into the mix with regard to
bind, apply, and call.


On 25 August 2014 10:54, Till Schneidereit <till at tillschneidereit.net>
wrote:

> On Mon, Aug 25, 2014 at 4:30 AM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
>
>> On 8/24/14, 10:26 PM, Mark Everitt wrote:
>>
>>> The problem remains that arrow functions make
>>> bind etc. unpredictable.
>>>
>>
>> I think part of Domenic's point is that return values of bind() also make
>> bind (and call/apply for that matter) unpredictable.
>>
>
> More fundamentally, I guess you could say that every function that doesn't
> use `this` makes `bind` unpredictable. Domenic's second example shows a
> function like that.
>
> I would argue that, if anything, arrow functions slightly improve
> predictability: before arrow functions, the only way to meaningfully
> "predict" the change in behavior that `bind` causes for a functions was by
> looking at its source code *and by ensuring that the function hasn't been
> bound already*. For arrow functions, you only need to inspect the source
> code. (Granted, this probably isn't *that* much of a real-world
> improvement.)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140825/171be67a/attachment-0001.html>


More information about the es-discuss mailing list