From cdfb5091bee1fd4d139cd972da6e6831b2dd4c5e Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Wed, 23 Dec 2009 20:48:55 -0500 Subject: [PATCH] more better super docs, better switch docs --- documentation/cs/switch.cs | 4 +++- documentation/index.html.erb | 18 +++++++++++++----- documentation/js/switch.js | 5 ++++- index.html | 27 ++++++++++++++++++++------- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/documentation/cs/switch.cs b/documentation/cs/switch.cs index 41bf9045..41109413 100644 --- a/documentation/cs/switch.cs +++ b/documentation/cs/switch.cs @@ -2,6 +2,8 @@ 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(). + if day is bingo_day + go_to_bingo() + go_dancing(). case "Sunday" then go_to_church() else go_to_work(). \ No newline at end of file diff --git a/documentation/index.html.erb b/documentation/index.html.erb index eba228f5..4fe61d1e 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -290,6 +290,12 @@ coffee-script --print app/scripts/*.cs > concatenation.js Base2, Prototype.js, JS.Class, etc. + The libraries provide syntactic sugar, but the built-in inheritance would + be completely usable if it weren't for one small exception: + it's very awkward to call super, the prototype object's + implementation of the current function. CoffeeScript converts + super() calls into calls against the immediate ancestor's + method of the same name.

<%= code_for('super', true) %> @@ -320,12 +326,14 @@ coffee-script --print app/scripts/*.cs > concatenation.js

Switch/Case/Else - Switch statements in JavaScript are fundamentally broken. You can only - do string comparisons, and need to break at the end of each case - statment to prevent falling through to the default case. CoffeeScript - compiles switch statements into if-else chains, allowing you to + Switch statements in JavaScript are rather broken. You can only + do string comparisons, and need to remember to break at the end of + every case statement to avoid accidentally falling through to + the default case. CoffeeScript + compiles switch statements into JavaScript if-else chains, allowing you to compare any object (via ===), preventing fall-through, and resulting - in a returnable expression. + in a returnable, assignable expression. To specify the default case, just + use else.

<%= code_for('switch') %> diff --git a/documentation/js/switch.js b/documentation/js/switch.js index 36a2a15e..53406faa 100644 --- a/documentation/js/switch.js +++ b/documentation/js/switch.js @@ -4,7 +4,10 @@ } else if (day === "Wednesday") { go_to_the_park(); } else if (day === "Saturday") { - day === bingo_day ? go_to_bingo() : null; + if (day === bingo_day) { + go_to_bingo(); + go_dancing(); + } } else if (day === "Sunday") { go_to_church(); } else { diff --git a/index.html b/index.html index 6f5e195c..bd610f4d 100644 --- a/index.html +++ b/index.html @@ -505,6 +505,12 @@ var three_to_six = nums.slice(3, 6 + 1); Base2, Prototype.js, JS.Class, etc. + The libraries provide syntactic sugar, but the built-in inheritance would + be completely usable if it weren't for one small exception: + it's very awkward to call super, the prototype object's + implementation of the current function. CoffeeScript converts + super() calls into calls against the immediate ancestor's + method of the same name.

Animal: => .
 Animal.prototype.move: meters =>
@@ -631,18 +637,22 @@ let_the_wild_rumpus_begin() unless answer 
       Switch/Case/Else
-      Switch statements in JavaScript are fundamentally broken. You can only
-      do string comparisons, and need to break at the end of each case
-      statment to prevent falling through to the default case. CoffeeScript
-      compiles switch statements into if-else chains, allowing you to
+      Switch statements in JavaScript are rather broken. You can only
+      do string comparisons, and need to remember to break at the end of 
+      every case statement to avoid accidentally falling through to 
+      the default case. CoffeeScript
+      compiles switch statements into JavaScript if-else chains, allowing you to
       compare any object (via ===), preventing fall-through, and resulting
-      in a returnable expression.
+      in a returnable, assignable expression. To specify the default case, just
+      use else.
     

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().
+  if day is bingo_day
+    go_to_bingo()
+    go_dancing().
 case "Sunday"    then go_to_church()
 else go_to_work().
 
if (day === "Tuesday") {
@@ -650,7 +660,10 @@ let_the_wild_rumpus_begin() unless answer else if (day === "Wednesday") {
   go_to_the_park();
 } else if (day === "Saturday") {
-  day === bingo_day ? go_to_bingo() : null;
+  if (day === bingo_day) {
+    go_to_bingo();
+    go_dancing();
+  }
 } else if (day === "Sunday") {
   go_to_church();
 } else {