what kind of problem is this fat arrow feature trying to solve ?

Benjamin (Inglor) Gruenbaum inglor at gmail.com
Wed Oct 2 04:14:26 PDT 2013

There are two things here:

 - In JS I (as well as most code in libraries I read) tend to use function
expressions a lot. The arrow notation is easier to read in my opinion. It's
shorter and more concise. That's a weak argument for it, but I think just
making the language more concise is an argument on its own.

 - While we're making function expressions shorter, let's fix `this`
function expresisons. Pretty much every host environment be it node, the
web browser or embedding uses deferred execution and event loop driven
concurrency at some level.

While there is nothing in JavaScript itself that dictates this sort of
concurrency in practice events are used extensively when coding JavaScript.
Using an object and adding handlers that need a reference to that object is
very common in the browser and in node.

It's very common in practice and having lexical this in arrow functions
seems very useful. An indicator might be that in languages that support it
like CoffeeScript you see it used all the time, and the fact you see people
using the `this=that/self/_this` ""pattern"" all the time. That pattern
introduces its own set of problems - for example it creates a closure scope
where one might not be needed and it's boilerplate.

Having fat arrow lets us solve that.

Benjamin Gruenbaum

---------- Forwarded message ----------
From: Andrea Giammarchi <andrea.giammarchi at gmail.com>
To: "Tab Atkins Jr." <jackalmage at gmail.com>
Cc: "es-discuss at mozilla.org" <es-discuss at mozilla.org>
Date: Tue, 1 Oct 2013 19:35:28 -0700
Subject: Re: what kind of problem is this fat arrow feature trying to solve
setTimeout accept extra arguments ... I write JavaScript that uses this

`setTimeout(callback, delay, arg1, arg2, argN, evenAnObject);`

so fat arrow does not solve much here, I can use self as first argument and
I am good.

`forEach` and all other arrays accept a second argument

`array.forEach(doStuff, boundContextObject);`

so fat arrow does not solve a thing in mostly all Array extras.

for **DOM** I use handlers as specified by **W3C** so that `{handleEvent:
function () {this}}` works better than any mess I could create with
callbacks that I won't be unable to remove later on (as I've said) ... so I
can use `removeEventListener(this)` in every method handled by that object.

So I actually wonder what kind of JavaScript **you** write because this was
a honest question but probably ... people not familiar with JS are the
answer: since developers ignore part of JS specs available since every then
we need a fat arrow to break old syntax to make the creation of self bound
function easier.

This would be already an answer so thanks for participating.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131002/6741c705/attachment.html>

More information about the es-discuss mailing list