From bebc5812e54d92fa34bd2020664854f0584396d4 Mon Sep 17 00:00:00 2001
From: Geoffrey Booth
square = (x) -> x * x
cube = (x) -> square(x) * x
-
var cube, square;
+
+square = function(x) {
+ return x * x;
+};
+
+cube = function(x) {
+ return square(x) * x;
+};
+
Functions may also have default values for arguments, which will be used
if the incoming argument is missing (null
or undefined
).
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 + "...";
+};
+
@@ -590,20 +624,20 @@ kids = song = ["do", "re", "mi", "fa", "so"]; singers = { - Jagger: "Rock", - Elvis: "Roll" + Jagger: "Rock", + Elvis: "Roll" }; bitlist = [1, 0, 1, 0, 0, 1, 1, 1, 0]; kids = { - brother: { - name: "Max", - age: 11 + brother: { + name: "Max", + age: 11 }, - sister: { - name: "Ida", - age: 9 + sister: { + name: "Ida", + age: 9 } };