Fat Arrow => for declaring an anonymous function with scope context preservation
String interpolation.
Splats and destructuring.
But that’s not the extent of CoffeeScript’s ergonomic improvements (in no particular order):
Everything is an expression. I love this the most about Ruby/Rust/Elm/etc. No need for explicit return keyword (in most cases, except when wanting to short circuit). The last “expression” in a function is automatically returned as its return value.
? to guard against possible undefined keys when doing nested object access (e.g. val = obj.?key.?might.?not.?exist will not crash. In JS you’d have to guard against every level of object access via if (obj && obj.key && obj.key.might && obj.key.might.not)
-> skinny arrow to not preserve scope context when declaring an anonymous function. In legitimate cases where you want a closure’s this (or @ syntactic sugar in CoffeeScript) to actually refer to the new anonymous function scope’s this or arguments, you don’t want to use a =>. In vanilla JS, that means writing out function(), in CoffeeScript, it’s a skinny arrow.
Not requiring parenthesis for function calls (e.g. alert "Hey ma, no parenths!").
Control flow expressions can be suffixed to a line (e.g. alert "You should see this if..." if truthy_value).
List Interpretation syntax for loops (Python-esque).
According to whom has CoffeeScript served its purpose?
A lot of the good features in Coffeescript like fat arrows made it in to ES6
Three major features certainly made it into ES6:
=>
for declaring an anonymous function with scope context preservationBut that’s not the extent of CoffeeScript’s ergonomic improvements (in no particular order):
Everything is an expression. I love this the most about Ruby/Rust/Elm/etc. No need for explicit
return
keyword (in most cases, except when wanting to short circuit). The last “expression” in a function is automatically returned as its return value.?
to guard against possible undefined keys when doing nested object access (e.g.val = obj.?key.?might.?not.?exist
will not crash. In JS you’d have to guard against every level of object access viaif (obj && obj.key && obj.key.might && obj.key.might.not)
->
skinny arrow to not preserve scope context when declaring an anonymous function. In legitimate cases where you want a closure’sthis
(or@
syntactic sugar in CoffeeScript) to actually refer to the new anonymous function scope’sthis
orarguments
, you don’t want to use a=>
. In vanilla JS, that means writing outfunction()
, in CoffeeScript, it’s a skinny arrow.Not requiring parenthesis for function calls (e.g.
alert "Hey ma, no parenths!"
).Control flow expressions can be suffixed to a line (e.g.
alert "You should see this if..." if truthy_value
).List Interpretation syntax for loops (Python-esque).
Try this in ES6:
(Tagged template literals + coercion from Array to String, har har har.)