Created
August 6, 2010 11:07
-
-
Save sebmarkbage/511175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, I like ECMAScript syntax way better.