@@ -56,6 +56,7 @@ <h2>Table of Contents</h2>
56
56
< a href ="#existence "> The Existence Operator</ a > < br />
57
57
< a href ="#aliases "> Aliases</ a > < br />
58
58
< a href ="#splats "> Splats</ a > < br />
59
+ < a href ="#arguments "> Arguments are Arrays</ a > < br />
59
60
< a href ="#while "> While Loops</ a > < br />
60
61
< a href ="#comprehensions "> Comprehensions (Arrays, Objects, and Ranges)</ a > < br />
61
62
< a href ="#slice_splice "> Array Slicing and Splicing with Ranges</ a > < br />
@@ -201,7 +202,7 @@ <h2 id="overview">Mini Overview</h2>
201
202
< a href ="documentation/underscore.html "> Underscore.coffee</ a > , a port
202
203
of < a href ="http://documentcloud.github.com/underscore/ "> Underscore.js</ a >
203
204
to CoffeeScript, which, when compiled, can pass the complete Underscore test suite.
204
- Or, clone the source and take a look in the
205
+ Or, clone the source and take a look in the
205
206
< a href ="http://github.com/jashkenas/coffee-script/tree/master/examples/ "> examples</ a > folder.
206
207
</ p >
207
208
@@ -631,6 +632,29 @@ <h2>Language Reference</h2>
631
632
alert("Gold: " + gold);
632
633
alert("Silver: " + silver);
633
634
alert("The Field: " + the_field);
635
+ ; '> run</ button > < br class ='clear ' /> </ div >
636
+
637
+ < p id ="arguments ">
638
+ < b class ="header "> Arguments are Arrays</ b >
639
+ If you reference the < b > arguments object</ b > directly, it will be converted
640
+ into a real Array, making all of the
641
+ < a href ="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array "> Array methods</ a >
642
+ available.
643
+ </ p >
644
+ < div class ='code '> < pre class ="idle "> < span class ="FunctionName "> backwards</ span > < span class ="Keyword "> :</ span > < span class ="Storage "> =></ span >
645
+ alert(arguments.reverse())
646
+
647
+ backwards(< span class ="String "> < span class ="String "> "</ span > stairway< span class ="String "> "</ span > </ span > , < span class ="String "> < span class ="String "> "</ span > to< span class ="String "> "</ span > </ span > , < span class ="String "> < span class ="String "> "</ span > heaven< span class ="String "> "</ span > </ span > )
648
+ </ pre > < pre class ="idle "> < span class ="Storage "> var</ span > backwards;
649
+ backwards < span class ="Keyword "> =</ span > < span class ="Storage "> function</ span > < span class ="FunctionName "> backwards</ span > () {
650
+ < span class ="Keyword "> return</ span > < span class ="LibraryFunction "> alert</ span > (< span class ="LibraryClassType "> Array</ span > .< span class ="LibraryConstant "> prototype</ span > .slice.< span class ="LibraryFunction "> call</ span > (arguments, < span class ="Number "> 0</ span > ).< span class ="LibraryFunction "> reverse</ span > ());
651
+ };
652
+ backwards(< span class ="String "> < span class ="String "> "</ span > stairway< span class ="String "> "</ span > </ span > , < span class ="String "> < span class ="String "> "</ span > to< span class ="String "> "</ span > </ span > , < span class ="String "> < span class ="String "> "</ span > heaven< span class ="String "> "</ span > </ span > );
653
+ </ pre > < button onclick ='javascript: var backwards;
654
+ backwards = function backwards() {
655
+ return alert(Array.prototype.slice.call(arguments, 0).reverse());
656
+ };
657
+ backwards("stairway", "to", "heaven");
634
658
; '> run</ button > < br class ='clear ' /> </ div >
635
659
636
660
< p id ="while ">
@@ -1030,8 +1054,8 @@ <h2>Language Reference</h2>
1030
1054
< p id ="blocks ">
1031
1055
< b class ="header "> Blocks</ b >
1032
1056
Many common looping functions (in Prototype, jQuery, and Underscore,
1033
- for example) take a single function as their final argument. To make
1034
- final functions easier to pass, CoffeeScript includes block syntax,
1057
+ for example) take a single function as their final argument. To make
1058
+ final functions easier to pass, CoffeeScript includes block syntax,
1035
1059
so you don't have to close the parentheses on the other side.
1036
1060
</ p >
1037
1061
< div class ='code '> < pre class ="idle "> < span class ="Keyword "> $</ span > (< span class ="String "> < span class ="String "> '</ span > table.list< span class ="String "> '</ span > </ span > ).each()< span class ="FunctionArgument "> table </ span > < span class ="Storage "> =></ span >
@@ -1165,7 +1189,7 @@ <h2 id="resources">Resources</h2>
1165
1189
</ li >
1166
1190
< li >
1167
1191
< a href ="http://github.com/jnicklas/bistro_car "> BistroCar</ a > < br />
1168
- A Rails plugin by
1192
+ A Rails plugin by
1169
1193
< a href ="http://github.com/jnicklas "> Jonas Nicklas</ a >
1170
1194
that includes CoffeeScript helpers,
1171
1195
bundling and minification.
@@ -1182,7 +1206,7 @@ <h2 id="contributing">Contributing</h2>
1182
1206
< ul >
1183
1207
< li >
1184
1208
A clean, safe syntax for manipulating the prototype chain, and performing
1185
- inheritance. < a href ="#inheritance "> < b > extends</ b > and < b > super</ b > </ a > are the start of this, but
1209
+ inheritance. < a href ="#inheritance "> < b > extends</ b > and < b > super</ b > </ a > are the start of this, but
1186
1210
aren't a complete answer.
1187
1211
</ li >
1188
1212
< li >
@@ -1210,12 +1234,17 @@ <h2 id="contributing">Contributing</h2>
1210
1234
1211
1235
< h2 id ="change_log "> Change Log</ h2 >
1212
1236
1237
+ < p >
1238
+ < b class ="header " style ="margin-top: 20px; "> 0.2.1</ b >
1239
+ Arguments objects are now converted into real arrays when referenced.
1240
+ </ p >
1241
+
1213
1242
< p >
1214
1243
< b class ="header " style ="margin-top: 20px; "> 0.2.0</ b >
1215
1244
Major release. Significant whitespace. Better statement-to-expression
1216
1245
conversion. Splats. Splice literals. Object comprehensions. Blocks.
1217
1246
The existence operator. Many thanks to all the folks who posted issues,
1218
- with special thanks to
1247
+ with special thanks to
1219
1248
< a href ="http://github.com/kamatsu "> Liam O'Connor-Davis</ a > for whitespace
1220
1249
and expression help.
1221
1250
</ p >
0 commit comments