(In all fairness, Andrea was merely, and quite explicitly so, asking for the rationale behind the fat arrow, not a scrutiny of his examples. Tab's sarcastic response was unnecessary on a whole different level, too.)
On Wed, Oct 2, 2013 at 1:14 PM, Benjamin (Inglor) Gruenbaum < ing...@gmail.com> wrote: > 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.giammar...@gmail.com> > To: "Tab Atkins Jr." <jackalm...@gmail.com> > Cc: "es-discuss@mozilla.org" <es-discuss@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 > feature. > > `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. > > br > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss