6 ms·
Implement arrow functions in v8
- feld 11y agoDo 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
- rubiquity 11y agoThen it seems like the perfect opportunity for you to learn something new and stretch your mind a little.
- JeremyBanks 11y agohttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- bsimpson 11y agoArrow functions are one of the improvements from JS Harmony (which was ratified last night). This commit moves them from "behind the experimental flag" to "shipping by default" in Chromium. It's a pretty big deal to people who write JS for a living.
- feld 11y agothat's what the synopsis of the post should have been, thanks
- towelguy 11y agoThey 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 11y agoSo 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.
- gfodor 11y agoYou are trolling, but arrow functions (unlike those defined with the function keyword) also bind this to that of the enclosing scope. The results in more intuitive behavior in most cases and less explicit bindings.
- eueueu 11y agoshrug it's still just code. It still does exactly the same thing as previous javascript code. Syntax changes are pretty boring IMHO, and as I said personally, I find this one much harder to read, more prone to errors, typos and confusion.
- kuschku 11y agoYes, but if you write a few thousand of those arrow functions, you will hate the useless function (a) { return b; } stuff, too.
- eueueu 11y agoIf you're writing a few thousand functions, you're doing something very wrong. It's like when languages make threads easy to create - and then programmers go away and use threads for everything! Maybe some verbosity is a good thing because it makes programmers think about whether they really want to do something a few thousand times.
- adrianpike 11y agoJavascript is a functional language. You _should_ be writing many functions, possibly thousands in a large codebase.
- teraflop 11y agoYour link goes to the same page as this post. Was it changed at some point?
- feld 11y agomust have, because it was going directly to the commit which didn't have any useful information.
- realusername 11y agoI'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 11y agoa=>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!
- jahewson 11y agoBecause writing: var self = this; foo(function(x) { return x + self.y; }); rather than: foo(x => x + this.y) is so much less error-prone?
- eueueu 11y agoThink about what would happen if you typo a single character in each example. If you miswrite "function" as "fnuction", you'll easily, quickly find out. If you miswrite => as >= it might take ages to track it down.
- wereHamster 11y agoThat's why you use static type checkers. If the function `foo` is defined as taking a function as its first argument (or even more precisely, a function which takes a number and returns a number), and you try to give it a boolean, then the static type checker will yell at you, and you'll just as easily find out as that fnuction typo.
- danbruc 11y agoWhat the heck is the second one supposed to mean? At first it looks a bit like low <= x <= high but with one comparison operator in the wrong direction. I guess it will first compare a and b evaluating to a boolean value, then implicitly convert this result to an integer and finally compare that to 7 again yielding a boolean value. If you write code like that confusion with the arrow notation is one of your smaller problems. EDIT: Now I got your point - you could accidentally assign a boolean value to a variable when you intended to create a function. One word - compile time type checking. Okay, four, Übersetzungszeittypprüfung in German.
- davexunit 11y agoNow 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-coming-to-chrome-45 http://wingolog.org/archives/2015/06/18/arrow-functions-comi...
- malandrew 11y agoAnyone 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.
- cozuya 11y agoOn the front end you can get babel to work with sourcemaps fairly easily depending on what build tool you use.
- bnoordhuis 11y agoIt'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.
- z3t4 11y agoIf 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);
- awalGarg 11y agoIt 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