mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
documentation waypoint
This commit is contained in:
5
documentation/cs/array_comprehensions.cs
Normal file
5
documentation/cs/array_comprehensions.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
# Eat lunch.
|
||||
lunch: food.eat() for food in ['toast', 'cheese', 'wine'].
|
||||
|
||||
# Zebra-stripe a table.
|
||||
highlight(row) for row, i in table if i % 2 is 0.
|
||||
2
documentation/cs/assignment.cs
Normal file
2
documentation/cs/assignment.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
greeting: "Hello CoffeeScript"
|
||||
difficulty: 0.5
|
||||
9
documentation/cs/conditionals.cs
Normal file
9
documentation/cs/conditionals.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
mood: greatly_improved if singing
|
||||
|
||||
if happy and knows_it
|
||||
claps_hands()
|
||||
cha_cha_cha().
|
||||
|
||||
date: if friday then sue else jill.
|
||||
|
||||
expensive ||= do_the_math()
|
||||
3
documentation/cs/embedded.cs
Normal file
3
documentation/cs/embedded.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
js: => `alert("Hello JavaScript");`.
|
||||
|
||||
js() if 10 > 9
|
||||
9
documentation/cs/expressions.cs
Normal file
9
documentation/cs/expressions.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
grade: student =>
|
||||
if student.excellent_work
|
||||
"A+"
|
||||
else if student.okay_stuff
|
||||
"B"
|
||||
else
|
||||
"C"..
|
||||
|
||||
eldest: if 24 > 21 then "Liz" else "Ike".
|
||||
2
documentation/cs/functions.cs
Normal file
2
documentation/cs/functions.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
square: x => x * x.
|
||||
cube: x => square(x) * x.
|
||||
3
documentation/cs/intro.cs
Normal file
3
documentation/cs/intro.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
# CoffeeScript on the left, JS on the right.
|
||||
|
||||
square: x => x * x.
|
||||
6
documentation/cs/objects_and_arrays.cs
Normal file
6
documentation/cs/objects_and_arrays.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
song: ["do", "re", "mi", "fa", "so"]
|
||||
ages: {
|
||||
max: 10
|
||||
ida: 9
|
||||
tim: 11
|
||||
}
|
||||
11
documentation/cs/punctuation.cs
Normal file
11
documentation/cs/punctuation.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
# Comments start with hash marks.
|
||||
|
||||
# Periods mark the end of a block.
|
||||
left_hand: if raining then umbrella else parasol.
|
||||
|
||||
# To signal the beginning of the next expression,
|
||||
# use "then", or a newline.
|
||||
left_hand: if raining
|
||||
umbrella
|
||||
else
|
||||
parasol.
|
||||
5
documentation/cs/scope.cs
Normal file
5
documentation/cs/scope.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
num: 1
|
||||
change_numbers: =>
|
||||
num: 2
|
||||
new_num: 3.
|
||||
new_num: change_numbers()
|
||||
2
documentation/cs/slices.cs
Normal file
2
documentation/cs/slices.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
nums: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
three_to_six: nums[3, 6]
|
||||
6
documentation/cs/strings.cs
Normal file
6
documentation/cs/strings.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
moby_dick: "Call me Ishmael. Some years ago --
|
||||
never mind how long precisely -- having little
|
||||
or no money in my purse, and nothing particular
|
||||
to interest me on shore, I thought I would sail
|
||||
about a little and see the watery part of the
|
||||
world..."
|
||||
21
documentation/cs/super.cs
Normal file
21
documentation/cs/super.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
Animal: => .
|
||||
Animal.prototype.move: meters =>
|
||||
alert(this.name + " moved " + meters + "m.").
|
||||
|
||||
Snake: name => this.name: name.
|
||||
Snake extends new Animal()
|
||||
Snake.prototype.move: =>
|
||||
alert("Slithering...")
|
||||
super(5).
|
||||
|
||||
Horse: name => this.name: name.
|
||||
Horse extends new Animal()
|
||||
Horse.prototype.move: =>
|
||||
alert("Galloping...")
|
||||
super(45).
|
||||
|
||||
sam: new Snake("Sammy the Python")
|
||||
tom: new Horse("Tommy the Palomino")
|
||||
|
||||
sam.move()
|
||||
tom.move()
|
||||
7
documentation/cs/switch.cs
Normal file
7
documentation/cs/switch.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
switch day
|
||||
case "Tuesday" then eat_breakfast()
|
||||
case "Wednesday" then go_to_the_park()
|
||||
case "Saturday"
|
||||
if day is bingo_day then go_to_bingo().
|
||||
case "Sunday" then go_to_church()
|
||||
else go_to_work().
|
||||
7
documentation/cs/try.cs
Normal file
7
documentation/cs/try.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
try
|
||||
all_hell_breaks_loose()
|
||||
cats_and_dogs_living_together()
|
||||
catch error
|
||||
print( error )
|
||||
finally
|
||||
clean_up().
|
||||
5
documentation/cs/while.cs
Normal file
5
documentation/cs/while.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
while demand > supply
|
||||
sell()
|
||||
restock().
|
||||
|
||||
while supply > demand then buy().
|
||||
Reference in New Issue
Block a user