r/javascript • • Mar 31 '17

ES2018 First Look - it changes everything

https://www.youtube.com/watch?v=s-G_RZ4RJLU
464 Upvotes

120 comments sorted by

View all comments

25

u/azangru Apr 01 '17

I actually listened to a fresh interview with Brendan Eich yesterday, where he said that the keyword function he chose when he was prototyping JavaScript turned out to be a bit on the longish side for the JavaScript parser, which negatively affected its speed; so when the video mentioned the shortcut for the function keyword, it sounded a little too real.

19

u/delventhalz Apr 01 '17

To be honest, I wouldn't mind being able to use fn or func.

3

u/Disgruntled__Goat Apr 01 '17

Why? I was under the impression no one uses function at all now.

2

u/inu-no-policemen Apr 01 '17
function foo() {...}

is much nicer than:

const foo = () => {...};

ESLint and TypeScript's compiler will complain about redeclaring functions. So, there really is no benefit whatsoever in practice. The const option is longer, less easy to scan, and you have to pseudo-declare your functions in the right order.

The only benefit is that it shows newbies that JS has first-class functions. I.e. that you can assign them to variables. Personally, I really don't care for that. First-class aren't that special anymore.

I'll always prefer the declarative option over an imperative one.

1

u/Disgruntled__Goat Apr 01 '17

The only benefit is that it shows newbies that JS has first-class functions. I.e. that you can assign them to variables.

You don't need the short function syntax for that.

const foo = function() { ... };

2

u/inu-no-policemen Apr 01 '17

Meant that it's the only benefit of using an assignment instead of a declaration.