Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Looks really similar to Coffeescript. Is it safe to say that this new Javascript feature is a direct result of Coffeescript's influence? I hope so: Javascript is full of little horrors like the 'this' keyword, and it seems like it took a whole new language to convince people that it needs fixing.


I think its absolutely because of languages like coffee script that JavaScript is changing, but don't take my word for it. You can find statments from standards makers to the same effect.


Really? I'd really like to see some references to that.

These kinds of changes have been floating around for javascript since long before coffeescript.


This is a great talk to watch about the development of JS. It's been a while since I watched it, but the point I was making, and the point I gleaned from this talk, is that new ideas need a test bed, and according to Eich Coffeescript is one of those places where new ideas are tested, and derived from.

http://vimeo.com/27911873

http://brendaneich.com/2011/08/my-txjs-talk-twitter-remix/


The Harmony project (named differently in the past) existed long long before Coffeescript.


I don't think it matters what came first. CoffeeScript has had a great effect on hearts, and minds because you can use it. It matters that CoffeeScript exists because people can wrap there head around new concepts and ideas. Only once people really understand an idea can we determine if it's good, or bad.

Fat arrow is well understood in the JS community because of CoffeeScript, and that is one reason why people are pushing for fat arrow to be accepted. I personally think CoffeeScripts has had a very large impact on the idea.


the this keyword still works exactly the same, just a terse syntax for functions and for function binding to the current scope.

currently, function(){} is the exact same as the proposed ()->{}, and (function(){}).bind(this) is the exact same as ()=>{}


This is not just about syntax. Unless using bind somehow grants the mentioned property that

>"Fat arrow functions do not have prototype properties, which makes them cheaper to make. They are immutable."


granted, but that sounds more like a micro optimization rather then significantly changing the behavior of the language


Fat arrow and yield operator? Looks more like c# to me...


yield has been in Mozilla for ages, like, Firefox 2.x. The inspiration was python's yield.


I think it's safe to say. Arrow functions have existed in many different languages, but this particular flavor of using the fat arrow to declare a "lexical `this`" function, where the value of "this" within the function body preserves the value of "this" outside, is in CoffeeScript:

http://coffeescript.org/#fat_arrow


Jeremy, would you mind sharing what the inspiration was for CoffeeScript's fat arrow? Was that token inspired by another language or was it something you just came up with on your own?


Sure -- the syntax for arrow functions has been floating around for ages, in Haskell, C#, and probably most relevant for me, the "stabby lambdas" in Ruby 1.9.

One of the first ideas with CoffeeScript was to simplify function syntax, mostly because JavaScript's anonymous functions are so useful and pervasive that you end up with a lot of this:

    _.each(toRemove, function(key){ delete data[key]; });
... where the "word" function there doesn't really tell you anything meaningful about what you're trying to accomplish.

Arrows were appealing for a shorthand function syntax because of their visual representation of what happens in a (pure) function. Input goes in one side, output comes out the other. The input determines, or points to, the output. Since we use parentheses symmetrically to group parameters to a function, both when you define a function and when you call one, we arrive at this:

    (input) -> output
... or with our initial example:

    _.each toRemove, (key) -> delete data[key]
That was the thinking. CoffeeScript actually originally used => for all functions, but the fat arrow distinction was introduced when we introduced bound (lexical "this") functions as an alternative to normal (dynamic "this") functions.


Thanks for the detailed response. I thought it might have been inspired from Haskell or Ruby, but was surprised to find out that C# has a similar syntactic feature. So I was curious if there was an "official" etymology. Sounds like an amalgamation of all of the above.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: