

Implement arrow functions in v8 - inglor
https://code.google.com/p/v8/issues/detail?id=2700#c45

======
feld
Do we just link to random commits now? I have no idea what arrow functions are
or why it would even matter to half the people who visit this site.

edit: after following 4 links I finally found the bug report about it

[https://code.google.com/p/v8/issues/detail?id=2700](https://code.google.com/p/v8/issues/detail?id=2700)

~~~
towelguy
They are a compact way to write anonymous functions in Javascript, so instead
of

    
    
        var square = function (a) { return a * a;}
    

You can write:

    
    
        var square = a => a * a;

~~~
eueueu
So basically, a useless hipster fashion lead fluffy syntax change, which
mainly makes code harder to read, and makes typos more common.

    
    
      // foo takes a function, and a boolean.
      // foo(a=>7, a>=2);
    

Really? That's easy to read is it? Eugh count me out.

~~~
phs2501
Verbosity is not clarity.

    
    
        list.map(function(x) { return x * 2; });
    

verses

    
    
        list.map(x => x * 2);
    

The actual functionality of the first is swallowed in visual noise (function,
return). Yes, it's something new to learn for Javascript programmers, but it's
useful and makes the meaning of code clearer.

That's not even touching on the this-binding element, which is also incredibly
useful in common Javascript code.

~~~
pekk
Just eliminating the words "function" and "return" doesn't make the code
clearer. Anyone competent with Javascript can easily read the first form. The
difference in time to read the expression may not even be measurable. If you
want to argue that it makes the code neater that's fine, but the meaning is
not made clearer by the substitution of sigils for words.

~~~
ubertaco
> Anyone competent with Javascript can easily read the first form

And anyone competent with _any_ language implementing map can easily read:

    
    
        users.map(user => user.name);
    

...without having to do any "skimming over" the noise. It's not a big
difference, you're right, but it's the kind of little thing that, when you let
it build up over time, gives you the "write-everything-in-triplicate" feel of
Java 6.

Further, you have to be _intimately_ familiar with Javascript to understand
why this is necessary:

    
    
        function fetchUserData(){
            var self = this;
            userService.fetchAllUsers()
                       .then(function(fetchedUsers){ self.users = fetchedUsers; });
        }
    

or even this:

    
    
        function fetchUserData(){
            userService.fetchAllUsers()
                       .then(function(fetchedUsers){ this.users = fetchedUsers; }.bind(this));
        }
    

as opposed to simply writing:

    
    
        function fetchUserData(){
            userService.fetchAllUsers()
                       .then(fetchedUsers => this.users = fetchedUsers);
        }

~~~
z3t4
Did you know you can do this!?

    
    
      someObject.foo = function() {
        someObject.bar = 123;
      }
    
      function Foo() {
        var Foo = this;
        Foo.bar = 456;
      }
    

Pro tip: Always do asynchronous operations Before presenting the object to the
program state. Or you will see "undefined" bugs in production!

------
realusername
I'm glad it's finally arriving, it been working in Firefox for quite a long
time and I'm happy to see v8 implementing this ! Arrow functions are so much
nicer to read and use.

~~~
eueueu

      a=>b<=7
      a>=b<=7
    

Can you not see the typos possible with this? The less characters you use for
something, the more error prone. There's a reason we don't write in regular
expression syntax.

Maybe I'm just getting old!

~~~
AshleysBrain
Who on earth would really write that? Surely you'd use the optional braces to
make it clearer:

    
    
        a => { return b <= 7; }
    

Sure you can write it without that, but only if you want to write willfully
unclear code to annoy people, like writing an entire function body on one
line. Just because you _can_ do that doesn't mean that functions are
inherently unclear.

~~~
ajanuary
More who on earth would really write a function that took a named argument,
ignored it, and compared a value in the outer scope.

All of the examples that look confusing are artificially simple and doing
things you wouldn't normally try to do.

------
davexunit
Now read the blog post about it! Andy Wingo is a great compiler hacker and he
writes about a lot of things that he works on.
[http://wingolog.org/archives/2015/06/18/arrow-functions-
comi...](http://wingolog.org/archives/2015/06/18/arrow-functions-coming-to-
chrome-45)

~~~
malandrew
Totally agree. Wingolog is an amazing blog and anyone curious about compilers
and v8 in general should check it out.

------
malandrew
Anyone have any idea when destructuring assignment is going to make it into
v8?

That is one of the features my colleagues most cite as justification for using
babel.js (I wouldn't mind destructuring assigment either). I would love to be
able to avoid transpilation since it adds overhead from making out our
toolchain more complex and makes debugging more difficult because stack traces
and line numbers don't necessarily match up.

~~~
bnoordhuis
It's in the works:
[https://code.google.com/p/v8/issues/detail?id=811](https://code.google.com/p/v8/issues/detail?id=811)

You can tell by the number of CLs that a lot of work has been done already but
there are a few more still in progress. It's probably still a few weeks out.

Disclaimer: I don't speak for the V8 team, I'm just an interested onlooker.

------
awalGarg
It has been reverted[1] now. History repeats itself.

[1] -
[https://code.google.com/p/v8/issues/detail?id=2700#c47](https://code.google.com/p/v8/issues/detail?id=2700#c47)

------
z3t4
If you use an anonymous function instead of a named function you'll probably
end up writing a comment to clarify ... :P

Sometimes the code explains itself though!?

    
    
      allowed = members.filter(member => member.age >= ageLimit);

