diff --git a/documentation/cs/aliases.cs b/documentation/cs/aliases.cs new file mode 100644 index 00000000..3bbbb490 --- /dev/null +++ b/documentation/cs/aliases.cs @@ -0,0 +1,5 @@ +launch() if ignition is on + +volume: 10 if band aint spinal_tap + +let_the_wild_rumpus_begin() unless answer is no diff --git a/documentation/cs/embedded.cs b/documentation/cs/embedded.cs index 5a4f0d24..400c15b4 100644 --- a/documentation/cs/embedded.cs +++ b/documentation/cs/embedded.cs @@ -1,3 +1,4 @@ -js: => `alert("Hello JavaScript");`. +hi: `function() { + return [document.title, "Hello JavaScript"].join(": "); +}` -js() if 10 > 9 \ No newline at end of file diff --git a/documentation/index.html.erb b/documentation/index.html.erb index b2ea5486..eba228f5 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -19,7 +19,7 @@
-CoffeeScript includes the conditional assignment operators: ||:, which only assigns a value to a variable if the variable's current value - is falsy, and &&:, which will only replace the value of + is falsy, and &&:, which only replaces the value of truthy variables.
@@ -257,15 +257,15 @@ coffee-script --print app/scripts/*.cs > concatenation.js <%= code_for('while') %>- Other JavaScript loops, such as for loops and do-while loops - can be mimicked by variations on while, but the hope is that you - won't need to do that with CoffeeScript, either because you're using + Other JavaScript loops, such as for loops and do-while loops + can be mimicked by variations on while, but the hope is that you + won't need to do that with CoffeeScript, either because you're using each (forEach) style iterators, or...
Array Comprehensions - For your looping needs, CoffeeScript provides array comprehensions + For your looping needs, CoffeeScript provides array comprehensions similar to Python's. They replace (and compile into) for loops, with optional guard clauses and the value of the current array index. Unlike for loops, array comprehensions are expressions, and can be returned @@ -287,7 +287,7 @@ coffee-script --print app/scripts/*.cs > concatenation.js JavaScript's prototypal inheritance has always been a bit of a brain-bender, with a whole family tree of libraries that provide a cleaner syntax for classical inheritance on top of JavaScript's prototypes: - Base2, + Base2, Prototype.js, JS.Class, etc.
@@ -298,24 +298,26 @@ coffee-script --print app/scripts/*.cs > concatenation.js If you ever need to interpolate literal JavaScript snippets, you can use backticks to pass JavaScript straight through. - <%= code_for('embedded', true) %> + <%= code_for('embedded', 'hi()') %>Aliases - Because the == operator frequently causes undesirable coercion, + Because the == operator frequently causes undesirable coercion, is intransitive, and has a different meaning than in other languages, CoffeeScript compiles == into ===, and != into !==. -
-- is also compiles into ===, + In addition, is compiles into ===, and aint into !==.
- + As in YAML, on and yes + are the same as boolean true, while off and no are boolean false.
- - ++ For single-line statements, unless can be used as the inverse of if. +
+ <%= code_for('aliases') %> +Switch/Case/Else Switch statements in JavaScript are fundamentally broken. You can only diff --git a/documentation/js/aliases.js b/documentation/js/aliases.js new file mode 100644 index 00000000..f30e00ea --- /dev/null +++ b/documentation/js/aliases.js @@ -0,0 +1,12 @@ +(function(){ + if (ignition === true) { + launch(); + } + var volume; + if (band !== spinal_tap) { + volume = 10; + } + if (!(answer === false)) { + let_the_wild_rumpus_begin(); + } +})(); \ No newline at end of file diff --git a/documentation/js/embedded.js b/documentation/js/embedded.js index 4686b688..3c16b185 100644 --- a/documentation/js/embedded.js +++ b/documentation/js/embedded.js @@ -1,8 +1,5 @@ (function(){ - var js = function() { - return alert("Hello JavaScript"); - }; - if (10 > 9) { - js(); - } + var hi = function() { + return [document.title, "Hello JavaScript"].join(": "); +}; })(); \ No newline at end of file diff --git a/index.html b/index.html index 4417434c..6f5e195c 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@
-var mood; if (singing) { mood = greatly_improved; @@ -378,7 +378,7 @@ expensive = expensive || CoffeeScript includes the conditional assignment operators: ||:, which only assigns a value to a variable if the variable's current value - is falsy, and &&:, which will only replace the value of + is falsy, and &&:, which only replaces the value of truthy variables. @@ -444,15 +444,15 @@ var eldest = 24 > 21 ? "Liz" : "Ike"; }
- Other JavaScript loops, such as for loops and do-while loops - can be mimicked by variations on while, but the hope is that you - won't need to do that with CoffeeScript, either because you're using + Other JavaScript loops, such as for loops and do-while loops + can be mimicked by variations on while, but the hope is that you + won't need to do that with CoffeeScript, either because you're using each (forEach) style iterators, or...
Array Comprehensions - For your looping needs, CoffeeScript provides array comprehensions + For your looping needs, CoffeeScript provides array comprehensions similar to Python's. They replace (and compile into) for loops, with optional guard clauses and the value of the current array index. Unlike for loops, array comprehensions are expressions, and can be returned @@ -502,7 +502,7 @@ var three_to_six = nums.slice(3, 6 + 1); JavaScript's prototypal inheritance has always been a bit of a brain-bender, with a whole family tree of libraries that provide a cleaner syntax for classical inheritance on top of JavaScript's prototypes: - Base2, + Base2, Prototype.js, JS.Class, etc.
@@ -584,39 +584,51 @@ tom.move(); If you ever need to interpolate literal JavaScript snippets, you can use backticks to pass JavaScript straight through. -js: => `alert("Hello JavaScript");`. ++;alert(hi());'>run: hi()hi: `function() { + return [document.title, "Hello JavaScript"].join(": "); +}` -js() if 10 > 9 -var js = function() { - return alert("Hello JavaScript"); +var hi = function() { +return [document.title, "Hello JavaScript"].join(": "); }; -if (10 > 9) { - js(); -} -
Aliases - Because the == operator frequently causes undesirable coercion, + Because the == operator frequently causes undesirable coercion, is intransitive, and has a different meaning than in other languages, CoffeeScript compiles == into ===, and != into !==. -
-- is also compiles into ===, + In addition, is compiles into ===, and aint into !==.
- + As in YAML, on and yes + are the same as boolean true, while off and no are boolean false.
- - ++ For single-line statements, unless can be used as the inverse of if. +
+launch() if ignition is on + +volume: 10 if band aint spinal_tap + +let_the_wild_rumpus_begin() unless answer is no +
if (ignition === true) { + launch(); +} +var volume; +if (band !== spinal_tap) { + volume = 10; +} +if (!(answer === false)) { + let_the_wild_rumpus_begin(); +} +
Switch/Case/Else
Switch statements in JavaScript are fundamentally broken. You can only
diff --git a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
index b788c281..cb348dcc 100644
--- a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
+++ b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
@@ -211,13 +211,13 @@