summaryrefslogtreecommitdiffhomepage
path: root/coffeescript.html.markdown
diff options
context:
space:
mode:
authorAdam <adam@adambard.com>2013-07-31 22:48:51 -0700
committerAdam <adam@adambard.com>2013-07-31 22:48:51 -0700
commita98f8eb2df975eba1a4c1a9d04be337ff6dba54f (patch)
tree664b5ca879938bb21550cbb4300f6eca9e451012 /coffeescript.html.markdown
parent27c0560fdfe7bed63d544f6b58a919fa3e24b46f (diff)
parentffe51f1af85e36ebdcf4fd5192e39ae07e79c94a (diff)
Merge branch 'master' of https://github.com/adambard/learnxinyminutes-docs
Diffstat (limited to 'coffeescript.html.markdown')
-rw-r--r--coffeescript.html.markdown55
1 files changed, 55 insertions, 0 deletions
diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown
new file mode 100644
index 00000000..429f10b5
--- /dev/null
+++ b/coffeescript.html.markdown
@@ -0,0 +1,55 @@
+---
+language: coffeescript
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+filename: coffeescript.coffee
+---
+
+``` coffeescript
+# CoffeeScript is a hipster language.
+# It goes with the trends of many modern languages.
+# So comments are like Ruby and Python, they use hashes.
+
+###
+Block comments are like these, and they translate directly to '/ *'s and '* /'s
+for the resulting JavaScript code.
+
+You should understand most of JavaScript semantices
+before continuing.
+###
+
+# Assignment:
+number = 42 #=> var number = 42;
+opposite = true #=> var opposite = true;
+
+# Conditions:
+number = -42 if opposite #=> if(opposite) { number = -42; }
+
+# Functions:
+square = (x) -> x * x #=> var square = function(x) { return x * x; }
+
+# Ranges:
+list = [1..5] #=> var list = [1, 2, 3, 4, 5];
+
+# Objects:
+math =
+ root: Math.sqrt
+ square: square
+ cube: (x) -> x * square x
+#=> var math = {
+# "root": Math.sqrt,
+# "square": square,
+# "cube": function(x) { return x * square(x); }
+#}
+
+# Splats:
+race = (winner, runners...) ->
+ 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) #=> ...
+```