diff --git a/documentation/coffee/objects_and_arrays.coffee b/documentation/coffee/objects_and_arrays.coffee index 18e1176d..9a839bf8 100644 --- a/documentation/coffee/objects_and_arrays.coffee +++ b/documentation/coffee/objects_and_arrays.coffee @@ -2,7 +2,7 @@ song = ["do", "re", "mi", "fa", "so"] singers = {Jagger: "Rock", Elvis: "Roll"} -matrix = [ +bitlist = [ 1, 0, 1 0, 0, 1 1, 1, 0 diff --git a/documentation/index.html.erb b/documentation/index.html.erb index a2fae864..3292a253 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -360,47 +360,46 @@ Expressions console by pressing the load button on the left.
- CoffeeScript uses Python-style significant whitespace: You don't need to - use semicolons ; to terminate expressions, ending - the line will do just as well. Semicolons can still be used to fit - multiple expressions onto a single line. Instead of using curly braces - { } to delimit blocks of code (like functions, + First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code. + You don't need to use semicolons ; to terminate expressions, + ending the line will do just as well, (although semicolons can still + be used to fit multiple expressions onto a single line.) + Instead of using curly braces + { } to surround blocks of code in functions, if-statements, - switch, and try/catch), + switch, and try/catch, use indentation.
You don't need to use parentheses to invoke a function if you're passing
- arguments:
print "coffee". The implicit call wraps forward
- to the end of the line or block expression.
-
- Within object literals, indentation can be used to create nested objects.
+ arguments. The implicit call wraps forward to the end of the line or block expression.
+ console.log sys.inspect object → console.log(sys.inspect(object));
Functions - Functions are defined by a list of parameters, an arrow, and the - function body. The empty function looks like this: -> + Functions are defined by an optional list of parameters in parentheses, + an arrow, and the function body. The empty function looks like this: + ->
<%= code_for('functions', 'cube(5)') %>- Functions may also have default values for arguments. + Functions may also have default values for arguments. Override the default + value by passing a non-null argument.
<%= code_for('default_args', 'fill("cup")') %>Objects and Arrays - Object and Array literals look very similar to their JavaScript cousins. - When each property is listed on its own line, the commas are - optional. Objects may be created using indentation instead of - explicit braces, similar to YAML. + The CoffeeScript literals for objects and arrays look very similar to + their JavaScript cousins. When each property is listed on its own line, + the commas are optional. Objects may be created using indentation instead + of explicit braces, similar to YAML.
- <%= code_for('objects_and_arrays', 'song.join(",")') %> + <%= code_for('objects_and_arrays', 'song.join(" ... ")') %>In JavaScript, you can't use reserved words, like class, as properties of an object, without quoting them as strings. CoffeeScript notices reserved words diff --git a/documentation/js/objects_and_arrays.js b/documentation/js/objects_and_arrays.js index 57b544df..8ae4af53 100644 --- a/documentation/js/objects_and_arrays.js +++ b/documentation/js/objects_and_arrays.js @@ -1,10 +1,10 @@ -var kids, matrix, singers, song; +var bitlist, kids, singers, song; song = ["do", "re", "mi", "fa", "so"]; singers = { Jagger: "Rock", Elvis: "Roll" }; -matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0]; +bitlist = [1, 0, 1, 0, 0, 1, 1, 1, 0]; kids = { brother: { name: "Max", diff --git a/index.html b/index.html index 11f1992c..b7ffe3b9 100644 --- a/index.html +++ b/index.html @@ -435,31 +435,29 @@ Expressions console by pressing the load button on the left.
- CoffeeScript uses Python-style significant whitespace: You don't need to - use semicolons ; to terminate expressions, ending - the line will do just as well. Semicolons can still be used to fit - multiple expressions onto a single line. Instead of using curly braces - { } to delimit blocks of code (like functions, + First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code. + You don't need to use semicolons ; to terminate expressions, + ending the line will do just as well, (although semicolons can still + be used to fit multiple expressions onto a single line.) + Instead of using curly braces + { } to surround blocks of code in functions, if-statements, - switch, and try/catch), + switch, and try/catch, use indentation.
You don't need to use parentheses to invoke a function if you're passing
- arguments:
print "coffee". The implicit call wraps forward
- to the end of the line or block expression.
-
- Within object literals, indentation can be used to create nested objects.
+ arguments. The implicit call wraps forward to the end of the line or block expression.
+ console.log sys.inspect object → console.log(sys.inspect(object));
Functions - Functions are defined by a list of parameters, an arrow, and the - function body. The empty function looks like this: -> + Functions are defined by an optional list of parameters in parentheses, + an arrow, and the function body. The empty function looks like this: + ->
square = (x) -> x * x cube = (x) -> square(x) * x @@ -478,7 +476,8 @@ cube = function(x) { return square(x) * x; };;alert(cube(5));'>run: cube(5)
- Functions may also have default values for arguments. + Functions may also have default values for arguments. Override the default + value by passing a non-null argument.
fill = (container, liquid = "coffee") -> "Filling the #{container} with #{liquid}..." @@ -506,16 +505,16 @@ fill = function(container, liquid) {Objects and Arrays - Object and Array literals look very similar to their JavaScript cousins. - When each property is listed on its own line, the commas are - optional. Objects may be created using indentation instead of - explicit braces, similar to YAML. + The CoffeeScript literals for objects and arrays look very similar to + their JavaScript cousins. When each property is listed on its own line, + the commas are optional. Objects may be created using indentation instead + of explicit braces, similar to YAML.
+};;alert(song.join(" ... "));'>run: song.join(" ... ")song = ["do", "re", "mi", "fa", "so"] singers = {Jagger: "Rock", Elvis: "Roll"} -matrix = [ +bitlist = [ 1, 0, 1 0, 0, 1 1, 1, 0 @@ -530,13 +529,13 @@ kids = age: 9 -var kids, matrix, singers, song; +
var bitlist, kids, singers, song; song = ["do", "re", "mi", "fa", "so"]; singers = { Jagger: "Rock", Elvis: "Roll" }; -matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0]; +bitlist = [1, 0, 1, 0, 0, 1, 1, 1, 0]; kids = { brother: { name: "Max", @@ -547,13 +546,13 @@ kids = { age: 9 } }; -
In JavaScript, you can't use reserved words, like class, as properties of an object, without quoting them as strings. CoffeeScript notices reserved words