diff --git a/documentation/coffee/blocks.coffee b/documentation/coffee/blocks.coffee
new file mode 100644
index 00000000..6f31ee16
--- /dev/null
+++ b/documentation/coffee/blocks.coffee
@@ -0,0 +1,4 @@
+$('table.list').each() table =>
+ $('tr.account', table).each() row =>
+ row.show()
+ row.highlight()
diff --git a/documentation/coffee/splats.coffee b/documentation/coffee/splats.coffee
new file mode 100644
index 00000000..de02d242
--- /dev/null
+++ b/documentation/coffee/splats.coffee
@@ -0,0 +1,25 @@
+gold: silver: the_field: "unknown"
+
+medalists: first, second, *rest =>
+ gold: first
+ silver: second
+ the_field: rest
+
+contenders: [
+ "Michael Phelps"
+ "Liu Xiang"
+ "Yao Ming"
+ "Allyson Felix"
+ "Shawn Johnson"
+ "Roman Sebrle"
+ "Guo Jingjing"
+ "Tyson Gay"
+ "Asafa Powell"
+ "Usain Bolt"
+]
+
+medalists(*contenders)
+
+alert("Gold: " + gold)
+alert("Silver: " + silver)
+alert("The Field: " + the_field)
\ No newline at end of file
diff --git a/documentation/index.html.erb b/documentation/index.html.erb
index 5cb307cd..d520428f 100644
--- a/documentation/index.html.erb
+++ b/documentation/index.html.erb
@@ -82,11 +82,13 @@
Conditionals, Ternaries, and Conditional Assignment
The Existence Operator
Aliases
+ Splats
While Loops
Comprehensions (Arrays, Objects, and Ranges)
Array Slicing and Splicing with Ranges
Everything is an Expression
Inheritance, and Calling Super from a Subclass
+ Blocks
Embedded JavaScript
Switch/When/Else
Try/Catch/Finally
@@ -101,9 +103,9 @@
CoffeeScript on the left, compiled JavaScript output on the right.
<%= code_for('overview', 'cubed_list') %> - +- For a longer CoffeeScript example, check out + For a longer CoffeeScript example, check out Underscore.coffee, a port of Underscore.js to CoffeeScript, which, when compiled, passes the complete Underscore test suite. @@ -141,7 +143,7 @@ gem install coffee-script
-r, --run
-e, --eval
Functions and Invocation Functions are defined by a list of parameters, an arrow, and the - function body. The empty function looks like this: => + function body. The empty function looks like this: =>. All + functions in CoffeeScript are named, for the benefit of debug messages.
<%= code_for('functions', 'cube(5)') %> @@ -261,7 +264,7 @@ coffee --print app/scripts/*.coffee > concatenation.js <%= code_for('assignment', 'greeting') %>Declarations of new variables are pushed up to the top of the nearest - lexical scope, so that assignment may always be used within expressions. + lexical scope, so that assignment may always be performed within expressions.
@@ -358,6 +361,15 @@ coffee --print app/scripts/*.coffee > concatenation.js
<%= code_for('aliases') %> ++ Splats + The JavaScript arguments object is a useful way to work with + functions that accept variable numbers of arguments. CoffeeScript provides + splats *, both for function definition as well as invocation, + making variable arguments a little bit more palatable. +
+ <%= code_for('splats', true) %> +While Loops The only low-level loop that CoffeeScript provides is the while loop. @@ -407,7 +419,7 @@ coffee --print app/scripts/*.coffee > concatenation.js array with new values (to splice it).
<%= code_for('splices', 'numbers') %> - +Everything is an Expression (at least, as much as possible) You might have noticed how even though we don't add return statements @@ -455,6 +467,15 @@ coffee --print app/scripts/*.coffee > concatenation.js
<%= code_for('super', true) %> ++ Blocks + Many common looping functions (in Prototype, jQuery, and Underscore, + for example) take a single function as their final argument. To functions + easier to pass, CoffeeScript includes Ruby-style block syntax, so you don't + have to close the parentheses on the other side. +
+ <%= code_for('blocks') %> +Embedded JavaScript If you ever need to interpolate literal JavaScript snippets, you can @@ -499,6 +520,11 @@ coffee --print app/scripts/*.coffee > concatenation.js
- For a longer CoffeeScript example, check out + For a longer CoffeeScript example, check out Underscore.coffee, a port of Underscore.js to CoffeeScript, which, when compiled, passes the complete Underscore test suite. @@ -206,7 +208,7 @@ gem install coffee-script
-r, --run
-e, --eval
Functions and Invocation Functions are defined by a list of parameters, an arrow, and the - function body. The empty function looks like this: => + function body. The empty function looks like this: =>. All + functions in CoffeeScript are named, for the benefit of debug messages.
square: x => x * x cube: x => square(x) * x @@ -350,7 +353,7 @@ difficulty = 0.5; ;alert(greeting);'>run: greeting
Declarations of new variables are pushed up to the top of the nearest - lexical scope, so that assignment may always be used within expressions. + lexical scope, so that assignment may always be performed within expressions.
@@ -539,6 +542,68 @@ let_the_wild_rumpus_begin() unless answer < speed_limit ? accelerate() : null;
+
+ Splats + The JavaScript arguments object is a useful way to work with + functions that accept variable numbers of arguments. CoffeeScript provides + splats *, both for function definition as well as invocation, + making variable arguments a little bit more palatable. +
+gold: silver: the_field: "unknown" + +medalists: first, second, *rest => + gold: first + silver: second + the_field: rest + +contenders: [ + "Michael Phelps" + "Liu Xiang" + "Yao Ming" + "Allyson Felix" + "Shawn Johnson" + "Roman Sebrle" + "Guo Jingjing" + "Tyson Gay" + "Asafa Powell" + "Usain Bolt" +] + +medalists(*contenders) + +alert("Gold: " + gold) +alert("Silver: " + silver) +alert("The Field: " + the_field) +
var contenders, gold, medalists, silver, the_field; +gold = silver = the_field = "unknown"; +medalists = function medalists(first, second) { + var rest; + rest = Array.prototype.slice.call(arguments, 2); + gold = first; + silver = second; + return the_field = rest; +}; +contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"]; +medalists.apply(this, contenders); +alert("Gold: " + gold); +alert("Silver: " + silver); +alert("The Field: " + the_field); +
While Loops
The only low-level loop that CoffeeScript provides is the while loop.
@@ -713,7 +778,7 @@ numbers.splice.apply(numbers, [run: numbers
Everything is an Expression (at least, as much as possible)
You might have noticed how even though we don't add return statements
@@ -933,6 +998,25 @@ sam.move();
tom.move();
;'>run
+ Blocks
+ Many common looping functions (in Prototype, jQuery, and Underscore,
+ for example) take a single function as their final argument. To functions
+ easier to pass, CoffeeScript includes Ruby-style block syntax, so you don't
+ have to close the parentheses on the other side.
+
Embedded JavaScript
If you ever need to interpolate literal JavaScript snippets, you can
@@ -1050,6 +1134,11 @@ world...";
-
+
+ $('table.list').each() table =>
+ $('tr.account', table).each() row =>
+ row.show()
+ row.highlight()
+
$('table.list').each(function(table) {
+ return $('tr.account', table).each(function(row) {
+ row.show();
+ return row.highlight();
+ });
+});
+
+ A Rails plugin by Jonas Nicklas that includes CoffeeScript helpers,
+ bundling and minification.
+ Contributing