Skip to content

Commit 4895e6d

Browse files
committed
docs for arguments conversion
1 parent 3d43c41 commit 4895e6d

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

‎documentation/coffee/arguments.coffee

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
backwards: =>
2+
alert(arguments.reverse())
3+
4+
backwards("stairway", "to", "heaven")

‎documentation/index.html.erb

+21-6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<a href="#existence">The Existence Operator</a><br />
8484
<a href="#aliases">Aliases</a><br />
8585
<a href="#splats">Splats</a><br />
86+
<a href="#arguments">Arguments are Arrays</a><br />
8687
<a href="#while">While Loops</a><br />
8788
<a href="#comprehensions">Comprehensions (Arrays, Objects, and Ranges)</a><br />
8889
<a href="#slice_splice">Array Slicing and Splicing with Ranges</a><br />
@@ -109,7 +110,7 @@
109110
<a href="documentation/underscore.html">Underscore.coffee</a>, a port
110111
of <a href="http://documentcloud.github.com/underscore/">Underscore.js</a>
111112
to CoffeeScript, which, when compiled, can pass the complete Underscore test suite.
112-
Or, clone the source and take a look in the
113+
Or, clone the source and take a look in the
113114
<a href="http://github.com/jashkenas/coffee-script/tree/master/examples/">examples</a> folder.
114115
</p>
115116

@@ -372,6 +373,15 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
372373
</p>
373374
<%= code_for('splats', true) %>
374375

376+
<p id="arguments">
377+
<b class="header">Arguments are Arrays</b>
378+
If you reference the <b>arguments object</b> directly, it will be converted
379+
into a real Array, making all of the
380+
<a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array">Array methods</a>
381+
available.
382+
</p>
383+
<%= code_for('arguments', true) %>
384+
375385
<p id="while">
376386
<b class="header">While Loops</b>
377387
The only low-level loop that CoffeeScript provides is the while loop.
@@ -472,8 +482,8 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
472482
<p id="blocks">
473483
<b class="header">Blocks</b>
474484
Many common looping functions (in Prototype, jQuery, and Underscore,
475-
for example) take a single function as their final argument. To make
476-
final functions easier to pass, CoffeeScript includes block syntax,
485+
for example) take a single function as their final argument. To make
486+
final functions easier to pass, CoffeeScript includes block syntax,
477487
so you don't have to close the parentheses on the other side.
478488
</p>
479489
<%= code_for('blocks') %>
@@ -524,7 +534,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
524534
</li>
525535
<li>
526536
<a href="http://github.com/jnicklas/bistro_car">BistroCar</a><br />
527-
A Rails plugin by
537+
A Rails plugin by
528538
<a href="http://github.com/jnicklas">Jonas Nicklas</a>
529539
that includes CoffeeScript helpers,
530540
bundling and minification.
@@ -541,7 +551,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
541551
<ul>
542552
<li>
543553
A clean, safe syntax for manipulating the prototype chain, and performing
544-
inheritance. <a href="#inheritance"><b>extends</b> and <b>super</b></a> are the start of this, but
554+
inheritance. <a href="#inheritance"><b>extends</b> and <b>super</b></a> are the start of this, but
545555
aren't a complete answer.
546556
</li>
547557
<li>
@@ -569,12 +579,17 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
569579

570580
<h2 id="change_log">Change Log</h2>
571581

582+
<p>
583+
<b class="header" style="margin-top: 20px;">0.2.1</b>
584+
Arguments objects are now converted into real arrays when referenced.
585+
</p>
586+
572587
<p>
573588
<b class="header" style="margin-top: 20px;">0.2.0</b>
574589
Major release. Significant whitespace. Better statement-to-expression
575590
conversion. Splats. Splice literals. Object comprehensions. Blocks.
576591
The existence operator. Many thanks to all the folks who posted issues,
577-
with special thanks to
592+
with special thanks to
578593
<a href="http://github.com/kamatsu">Liam O'Connor-Davis</a> for whitespace
579594
and expression help.
580595
</p>

‎documentation/js/arguments.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(function(){
2+
var backwards;
3+
backwards = function backwards() {
4+
return alert(Array.prototype.slice.call(arguments, 0).reverse());
5+
};
6+
backwards("stairway", "to", "heaven");
7+
})();

‎index.html

+35-6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ <h2>Table of Contents</h2>
5656
<a href="#existence">The Existence Operator</a><br />
5757
<a href="#aliases">Aliases</a><br />
5858
<a href="#splats">Splats</a><br />
59+
<a href="#arguments">Arguments are Arrays</a><br />
5960
<a href="#while">While Loops</a><br />
6061
<a href="#comprehensions">Comprehensions (Arrays, Objects, and Ranges)</a><br />
6162
<a href="#slice_splice">Array Slicing and Splicing with Ranges</a><br />
@@ -201,7 +202,7 @@ <h2 id="overview">Mini Overview</h2>
201202
<a href="documentation/underscore.html">Underscore.coffee</a>, a port
202203
of <a href="http://documentcloud.github.com/underscore/">Underscore.js</a>
203204
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
205206
<a href="http://github.com/jashkenas/coffee-script/tree/master/examples/">examples</a> folder.
206207
</p>
207208

@@ -631,6 +632,29 @@ <h2>Language Reference</h2>
631632
alert("Gold: " + gold);
632633
alert("Silver: " + silver);
633634
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">=&gt;</span>
645+
alert(arguments.reverse())
646+
647+
backwards(<span class="String"><span class="String">&quot;</span>stairway<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>to<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>heaven<span class="String">&quot;</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">&quot;</span>stairway<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>to<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>heaven<span class="String">&quot;</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");
634658
;'>run</button><br class='clear' /></div>
635659

636660
<p id="while">
@@ -1030,8 +1054,8 @@ <h2>Language Reference</h2>
10301054
<p id="blocks">
10311055
<b class="header">Blocks</b>
10321056
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,
10351059
so you don't have to close the parentheses on the other side.
10361060
</p>
10371061
<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">=&gt;</span>
@@ -1165,7 +1189,7 @@ <h2 id="resources">Resources</h2>
11651189
</li>
11661190
<li>
11671191
<a href="http://github.com/jnicklas/bistro_car">BistroCar</a><br />
1168-
A Rails plugin by
1192+
A Rails plugin by
11691193
<a href="http://github.com/jnicklas">Jonas Nicklas</a>
11701194
that includes CoffeeScript helpers,
11711195
bundling and minification.
@@ -1182,7 +1206,7 @@ <h2 id="contributing">Contributing</h2>
11821206
<ul>
11831207
<li>
11841208
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
11861210
aren't a complete answer.
11871211
</li>
11881212
<li>
@@ -1210,12 +1234,17 @@ <h2 id="contributing">Contributing</h2>
12101234

12111235
<h2 id="change_log">Change Log</h2>
12121236

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+
12131242
<p>
12141243
<b class="header" style="margin-top: 20px;">0.2.0</b>
12151244
Major release. Significant whitespace. Better statement-to-expression
12161245
conversion. Splats. Splice literals. Object comprehensions. Blocks.
12171246
The existence operator. Many thanks to all the folks who posted issues,
1218-
with special thanks to
1247+
with special thanks to
12191248
<a href="http://github.com/kamatsu">Liam O'Connor-Davis</a> for whitespace
12201249
and expression help.
12211250
</p>

0 commit comments

Comments
 (0)