mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
documentation waypoint
This commit is contained in:
parent
dcc70e5ab0
commit
c7fa9c320a
42 changed files with 1026 additions and 53 deletions
16
documentation/js/array_comprehensions.js
Normal file
16
documentation/js/array_comprehensions.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
(function(){
|
||||
var lunch;
|
||||
var a = ['toast', 'cheese', 'wine'];
|
||||
var d = [];
|
||||
for (var b=0, c=a.length; b<c; b++) {
|
||||
var food = a[b];
|
||||
d[b] = food.eat();
|
||||
}
|
||||
lunch = d;
|
||||
var e = table;
|
||||
for (var f=0, g=e.length; f<g; f++) {
|
||||
var row = e[f];
|
||||
var i = f;
|
||||
i % 2 === 0 ? highlight(row) : null;
|
||||
}
|
||||
})();
|
4
documentation/js/assignment.js
Normal file
4
documentation/js/assignment.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
(function(){
|
||||
var greeting = "Hello CoffeeScript";
|
||||
var difficulty = 0.5;
|
||||
})();
|
12
documentation/js/conditionals.js
Normal file
12
documentation/js/conditionals.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
(function(){
|
||||
var mood;
|
||||
if (singing) {
|
||||
mood = greatly_improved;
|
||||
}
|
||||
if (happy && knows_it) {
|
||||
claps_hands();
|
||||
cha_cha_cha();
|
||||
}
|
||||
var date = friday ? sue : jill;
|
||||
expensive = expensive || do_the_math();
|
||||
})();
|
8
documentation/js/embedded.js
Normal file
8
documentation/js/embedded.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
(function(){
|
||||
var js = function() {
|
||||
return alert("Hello JavaScript");
|
||||
};
|
||||
if (10 > 9) {
|
||||
js();
|
||||
}
|
||||
})();
|
12
documentation/js/expressions.js
Normal file
12
documentation/js/expressions.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
(function(){
|
||||
var grade = function(student) {
|
||||
if (student.excellent_work) {
|
||||
return "A+";
|
||||
} else if (student.okay_stuff) {
|
||||
return "B";
|
||||
} else {
|
||||
return "C";
|
||||
}
|
||||
};
|
||||
var eldest = 24 > 21 ? "Liz" : "Ike";
|
||||
})();
|
3
documentation/js/expressions_assignment.js
Normal file
3
documentation/js/expressions_assignment.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
(function(){
|
||||
|
||||
})();
|
8
documentation/js/functions.js
Normal file
8
documentation/js/functions.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
(function(){
|
||||
var square = function(x) {
|
||||
return x * x;
|
||||
};
|
||||
var cube = function(x) {
|
||||
return square(x) * x;
|
||||
};
|
||||
})();
|
5
documentation/js/intro.js
Normal file
5
documentation/js/intro.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
(function(){
|
||||
var square = function(x) {
|
||||
return x * x;
|
||||
};
|
||||
})();
|
8
documentation/js/objects_and_arrays.js
Normal file
8
documentation/js/objects_and_arrays.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
(function(){
|
||||
var song = ["do", "re", "mi", "fa", "so"];
|
||||
var ages = {
|
||||
max: 10,
|
||||
ida: 9,
|
||||
tim: 11
|
||||
};
|
||||
})();
|
4
documentation/js/punctuation.js
Normal file
4
documentation/js/punctuation.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
(function(){
|
||||
var left_hand = raining ? umbrella : parasol;
|
||||
left_hand = raining ? umbrella : parasol;
|
||||
})();
|
9
documentation/js/scope.js
Normal file
9
documentation/js/scope.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
(function(){
|
||||
var num = 1;
|
||||
var change_numbers = function() {
|
||||
num = 2;
|
||||
var new_num = 3;
|
||||
return new_num;
|
||||
};
|
||||
var new_num = change_numbers();
|
||||
})();
|
4
documentation/js/slices.js
Normal file
4
documentation/js/slices.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
(function(){
|
||||
var nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
var three_to_six = nums.slice(3, 6 + 1);
|
||||
})();
|
8
documentation/js/strings.js
Normal file
8
documentation/js/strings.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
(function(){
|
||||
var 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...";
|
||||
})();
|
28
documentation/js/super.js
Normal file
28
documentation/js/super.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
(function(){
|
||||
var Animal = function() {
|
||||
|
||||
};
|
||||
Animal.prototype.move = function(meters) {
|
||||
return alert(this.name + " moved " + meters + "m.");
|
||||
};
|
||||
var Snake = function(name) {
|
||||
this.name = name;
|
||||
};
|
||||
Snake.prototype = new Animal();
|
||||
Snake.prototype.move = function() {
|
||||
alert("Slithering...");
|
||||
return this.constructor.prototype.move.call(this, 5);
|
||||
};
|
||||
var Horse = function(name) {
|
||||
this.name = name;
|
||||
};
|
||||
Horse.prototype = new Animal();
|
||||
Horse.prototype.move = function() {
|
||||
alert("Galloping...");
|
||||
return this.constructor.prototype.move.call(this, 45);
|
||||
};
|
||||
var sam = new Snake("Sammy the Python");
|
||||
var tom = new Horse("Tommy the Palomino");
|
||||
sam.move();
|
||||
tom.move();
|
||||
})();
|
13
documentation/js/switch.js
Normal file
13
documentation/js/switch.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
(function(){
|
||||
if (day === "Tuesday") {
|
||||
eat_breakfast();
|
||||
} else if (day === "Wednesday") {
|
||||
go_to_the_park();
|
||||
} else if (day === "Saturday") {
|
||||
day === bingo_day ? go_to_bingo() : null;
|
||||
} else if (day === "Sunday") {
|
||||
go_to_church();
|
||||
} else {
|
||||
go_to_work();
|
||||
}
|
||||
})();
|
10
documentation/js/try.js
Normal file
10
documentation/js/try.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
(function(){
|
||||
try {
|
||||
all_hell_breaks_loose();
|
||||
cats_and_dogs_living_together();
|
||||
} catch (error) {
|
||||
print(error);
|
||||
} finally {
|
||||
clean_up();
|
||||
}
|
||||
})();
|
9
documentation/js/while.js
Normal file
9
documentation/js/while.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
(function(){
|
||||
while (demand > supply) {
|
||||
sell();
|
||||
restock();
|
||||
}
|
||||
while (supply > demand) {
|
||||
buy();
|
||||
}
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue