summaryrefslogtreecommitdiffhomepage
path: root/coffeescript.html.markdown
diff options
context:
space:
mode:
authorXavier Yao <xavieryao@live.cn>2014-02-05 21:37:17 +0800
committerXavier Yao <xavieryao@live.cn>2014-02-05 21:37:17 +0800
commita089ef9b0d9a287e0b90f33f4c40b28b7f992783 (patch)
tree53e3050e0d79010a6b5ec150d4ebe00787116ebe /coffeescript.html.markdown
parenta44935283a6caf456ab7d058cbcecbfe63bceaa3 (diff)
Expend CoffeeScript doc
Diffstat (limited to 'coffeescript.html.markdown')
-rw-r--r--coffeescript.html.markdown42
1 files changed, 41 insertions, 1 deletions
diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown
index c61cad67..86c875ba 100644
--- a/coffeescript.html.markdown
+++ b/coffeescript.html.markdown
@@ -2,9 +2,13 @@
language: coffeescript
contributors:
- ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao"], "http://github.com/xavieryao"]
filename: coffeescript.coffee
---
+CoffeeScript is a little language that compiles one-to-one into the equivalent JavaScript, and there is no interpretation at runtime.
+As one of the succeeders of JavaScript, CoffeeScript tries its best to output readable, pretty-printed and smooth-running JavaScript codes working well in every JavaScript runtime.
+
See also [the CoffeeScript website](http://coffeescript.org/), which has a complete tutorial on CoffeeScript.
``` coffeescript
@@ -30,6 +34,17 @@ number = -42 if opposite #=> if(opposite) { number = -42; }
# Functions:
square = (x) -> x * x #=> var square = function(x) { return x * x; }
+fill = (container, liquid = "coffee") ->
+ "Filling the #{container} with #{liquid}..."
+#=>var fill;
+#
+#fill = function(container, liquid) {
+# if (liquid == null) {
+# liquid = "coffee";
+# }
+# return "Filling the " + container + " with " + liquid + "...";
+#};
+
# Ranges:
list = [1..5] #=> var list = [1, 2, 3, 4, 5];
@@ -47,11 +62,36 @@ math =
# Splats:
race = (winner, runners...) ->
print winner, runners
+#=>race = function() {
+# var runners, winner;
+# winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(winner, runners);
+#};
# Existence:
alert "I knew it!" if elvis?
#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); }
# Array comprehensions:
-cubes = (math.cube num for num in list) #=> ...
+cubes = (math.cube num for num in list)
+#=>cubes = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = list.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(math.cube(num));
+# }
+# return _results;
+# })();
+
+foods = ['broccoli', 'spinach', 'chocolate']
+eat food for food in foods when food isnt 'chocolate'
+#=>foods = ['broccoli', 'spinach', 'chocolate'];
+#
+#for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
+# food = foods[_k];
+# if (food !== 'chocolate') {
+# eat(food);
+# }
+#}
```