10 ms·
Not mentioned are ES6's arrow functions that capture the `this` value of the enclosing context. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
by _mtr 12y ago
Not mentioned are ES6's arrow functions that capture the `this` value of the enclosing context.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- jschrf 12y agoTypeScript has these and they're marvelous. They make writing functional style code very enjoyable and not having to capture `this` yourself is alone justification for this developer to never go back to pure JavaScript.
- krilnon 12y agoMight you go back when ES6 is widely supported by browsers / Node? I don't mind either way, but since the parent comment mentioned that arrow functions were coming to JS, it was interesting that you specifically said 'never', rather than 'until ES6'.
- jschrf 12y agoYeah I realize that may not have been the clearest statement, thanks. While ES6 is nice, it just doesn't have the elegance and utility of some of the other TypeScript things like generics and the interfacing system. Also, it will probably be a long time until it can be widely used, given the existence of certain browsers and versions.
- AnkhMorporkian 12y agoI think the new arrow functions are neat, but am I the only one who never really found it a hassle to throw a .bind(this) on a function?
- bshimmin 12y agoAside from the fact that your "never" somewhat dismisses the first however many years of web development (up to IE9) when `Function.prototype.bind` couldn't universally be expected to be supported, surely having a nice piece of syntax which is both shorter than writing out `function` and serves the purpose of binding the function in the way that, a good majority of the time, you actually want it bound, is a good thing? As someone who's spent a lot of time writing CoffeeScript, I think ES6's fat arrows are a great thing, though I have my usual concerns about their confusing the hell out of people who may well have been writing JavaScript for a long time but in environments where they don't necessarily get exposed to new and exciting stuff. But hey, that's progress, I guess.
- acjohnson55 12y agoI agree. Fat arrow is a massive improvement. Not just for its extremely logical handling of "this", which 95% of the time is the behavior I want, but also because it eliminates a massive amount of syntax noise when programming functionally.
- AnkhMorporkian 12y agoSure, my .bind was a little insensitive to those who had to suffer through ES3, but honestly I thought we were pretty much ignoring the 90s.
- bshimmin 12y agoYou say "the 90s", I say "2011". Potayto, potahto!
- jschrf 12y agoNot supported in ES3, IIRC.
- ulisesrmzroche 12y agoI think it adds too much line noise, especially if people start nesting callbacks.