Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created August 6, 2010 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmarkbage/511175 to your computer and use it in GitHub Desktop.
Save sebmarkbage/511175 to your computer and use it in GitHub Desktop.
// A nicer comparison of CoffeeScript syntax compared to manual ECMAScript Harmony style syntax
// Assignment:
let number = 42,
opposite = true
// Conditions:
if (opposite) number = -42
// Functions:
let square = function(x) x * x
// Arrays:
let list = [1, 2, 3, 4, 5]
// Objects:
let math = {
root: Math.sqrt,
square: square,
cube: function(x) x * square(x)
}
// Splats:
let race = function(winner, ...runners) print(winner, runners)
// Existence:
if (elvis != null) alert("I knew it!")
// Array comprehensions:
let cubes = list.map(math.cube)
# Sample CoffeeScript from the CoffeeScript front page http://jashkenas.github.com/coffee-script/
# Assignment:
number = 42
opposite = true
# Conditions:
number = -42 if opposite
# Functions:
square = (x) -> x * x
# Arrays:
list = [1, 2, 3, 4, 5]
# Objects:
math =
root: Math.sqrt
square: square
cube: (x) -> x * square x
# Splats:
race = (winner, runners...) ->
print winner, runners
# Existence:
alert "I knew it!" if elvis?
# Array comprehensions:
cubes = math.cube num for num in list
@subtleGradient
Copy link

Wow, I like ECMAScript syntax way better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment