CoffeeScript 0.7.0 is on the books.
This commit is contained in:
parent
e56af4967c
commit
677c7edf3f
|
@ -6,4 +6,6 @@ letTheWildRumpusBegin() unless answer is no
|
|||
|
||||
if car.speed < limit then accelerate()
|
||||
|
||||
winner: yes if pick in [47, 92, 13]
|
||||
|
||||
print "My name is " + @name
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$('.account').css {class: 'active'}
|
|
@ -5,6 +5,6 @@ if this.studyingEconomics
|
|||
|
||||
# Nursery Rhyme
|
||||
num: 6
|
||||
lyrics: while num -= 1
|
||||
lyrics: while num: - 1
|
||||
num + " little monkeys, jumping on the bed.
|
||||
One fell out and bumped his head."
|
||||
|
|
|
@ -172,7 +172,7 @@ if possible.</p> </td> <td class="code"> <
|
|||
<span class="k">return</span> <span class="p">[]</span> <span class="k">if</span> <span class="nx">len</span> <span class="o"><=</span> <span class="mi">0</span>
|
||||
<span class="nv">range: </span> <span class="k">new</span> <span class="nb">Array</span> <span class="nx">len</span>
|
||||
<span class="nv">idx: </span> <span class="mi">0</span>
|
||||
<span class="k">while</span> <span class="kc">true</span>
|
||||
<span class="nx">loop</span>
|
||||
<span class="k">return</span> <span class="nx">range</span> <span class="k">if</span> <span class="p">(</span><span class="k">if</span> <span class="nx">step</span> <span class="o">></span> <span class="mi">0</span> <span class="k">then</span> <span class="nx">i</span> <span class="o">-</span> <span class="nx">stop</span> <span class="k">else</span> <span class="nx">stop</span> <span class="o">-</span> <span class="nx">i</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span>
|
||||
<span class="nx">range</span><span class="p">[</span><span class="nx">idx</span><span class="p">]</span><span class="o">:</span> <span class="nx">i</span>
|
||||
<span class="nx">idx</span><span class="o">++</span>
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<a href="#conditionals">Conditionals, Ternaries, and Conditional Assignment</a>
|
||||
<a href="#aliases">Aliases</a>
|
||||
<a href="#splats">Splats...</a>
|
||||
<a href="#while">While & Until Loops</a>
|
||||
<a href="#while">While, Until, and Loop</a>
|
||||
<a href="#comprehensions">Comprehensions (Arrays, Objects, and Ranges)</a>
|
||||
<a href="#slice_splice">Array Slicing and Splicing with Ranges</a>
|
||||
<a href="#expressions">Everything is an Expression</a>
|
||||
|
@ -124,8 +124,7 @@ alert reverse '.eeffoC yrT'</textarea></div>
|
|||
it compiles into clean JavaScript (the good parts) that can use existing
|
||||
JavaScript libraries seamlessly, and passes through
|
||||
<a href="http://www.jslint.com/">JSLint</a> without warnings. The compiled
|
||||
output is quite readable — pretty-printed, with comments
|
||||
preserved intact.
|
||||
output is pretty-printed and quite readable.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
@ -380,6 +379,12 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
|||
and match the two styles.
|
||||
</p>
|
||||
<%= code_for('objects_and_arrays', 'song.join(",")') %>
|
||||
<p>
|
||||
In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties
|
||||
of an object, without quoting them as strings. CoffeeScript notices and quotes
|
||||
them for you, so you don't have to worry about it (say, when using jQuery).
|
||||
</p>
|
||||
<%= code_for('objects_reserved') %>
|
||||
|
||||
<p>
|
||||
<span id="lexical_scope" class="bookmark"></span>
|
||||
|
@ -470,6 +475,10 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
|||
<p>
|
||||
As a shortcut for <tt>this.property</tt>, you can use <tt>@property</tt>.
|
||||
</p>
|
||||
<p>
|
||||
You can use <tt>in</tt> to test for array presence, and <tt>of</tt> to
|
||||
test for JavaScript object-key presence.
|
||||
</p>
|
||||
<%= code_for('aliases') %>
|
||||
|
||||
<p>
|
||||
|
@ -484,7 +493,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
|||
|
||||
<p>
|
||||
<span id="while" class="bookmark"></span>
|
||||
<b class="header">While & Until Loops</b>
|
||||
<b class="header">While, Until, and Loop</b>
|
||||
The only low-level loop that CoffeeScript provides is the <b>while</b> loop. The
|
||||
main difference from JavaScript is that the <b>while</b> loop can be used
|
||||
as an expression, returning an array containing the result of each iteration
|
||||
|
@ -492,9 +501,10 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
|||
</p>
|
||||
<%= code_for('while', 'lyrics.join("\n")') %>
|
||||
<p>
|
||||
For readability, the <b>until</b> loop serves as an inverted <b>while</b> loop.
|
||||
For readability, the <b>until</b> keyword is equivalent to <tt>while not</tt>,
|
||||
and the <b>loop</b> keyword is equivalent to <tt>while true</tt>.
|
||||
Other JavaScript loops, such as <b>for</b> loops and <b>do-while</b> loops
|
||||
can be mimicked by variations on <b>while</b>, but the hope is that you
|
||||
can be mimicked by variations on <b>loop</b>, but the hope is that you
|
||||
won't need to do that with CoffeeScript, either because you're using
|
||||
<b>each</b> (<b>forEach</b>) style iterators, or...
|
||||
</p>
|
||||
|
@ -893,6 +903,11 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
|||
— a custom filter for rendering CoffeeScript inline within
|
||||
<a href="http://haml-lang.com/">HAML</a> templates.
|
||||
</li>
|
||||
<li>
|
||||
<b>jashkenas</b>'s <a href="http://jashkenas.github.com/docco/">Docco</a>
|
||||
— A quick-and-dirty literate-programming-style documentation generator
|
||||
for CoffeeScript. Used to produce the annotated source.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>
|
||||
|
@ -914,6 +929,23 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
|||
<span id="change_log" class="bookmark"></span>
|
||||
Change Log
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
<b class="header" style="margin-top: 20px;">0.7.0</b>
|
||||
Official CoffeeScript variable style is now camelCase, as in JavaScript.
|
||||
Reserved words are now allowed as object keys, and will be quoted for you.
|
||||
Range comprehensions now generate cleaner code, but you have to specify <tt>by -1</tt>
|
||||
if you'd like to iterate downward. Reporting of syntax errors is greatly
|
||||
improved from the previous release. Running <tt>coffee</tt> with no arguments
|
||||
now launches the REPL, with Readline support. The <tt>&-</tt> bind operator
|
||||
has been removed from CoffeeScript. The <tt>loop</tt> keyword was added,
|
||||
which is equivalent to a <tt>while true</tt> loop. Comprehensions that contain
|
||||
closures will now close over their variables, like the semantics of a <tt>forEach</tt>.
|
||||
You can now use bound function in class definitions (bound to the instance).
|
||||
For consistency, <tt>a in b</tt> is now an array presence check, and <tt>a of b</tt>
|
||||
is an object-key check. Comments are no longer passed through to the generated
|
||||
JavaScript.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b class="header" style="margin-top: 20px;">0.6.2</b>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function(){
|
||||
var volume;
|
||||
var volume, winner;
|
||||
if (ignition === true) {
|
||||
launch();
|
||||
}
|
||||
|
@ -10,5 +10,8 @@
|
|||
letTheWildRumpusBegin();
|
||||
}
|
||||
car.speed < limit ? accelerate() : null;
|
||||
if (47 === pick || 92 === pick || 13 === pick) {
|
||||
winner = true;
|
||||
}
|
||||
print("My name is " + this.name);
|
||||
})();
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
(function(){
|
||||
$('.account').css({
|
||||
'class': 'active'
|
||||
});
|
||||
})();
|
57
index.html
57
index.html
|
@ -32,7 +32,7 @@
|
|||
<a href="#conditionals">Conditionals, Ternaries, and Conditional Assignment</a>
|
||||
<a href="#aliases">Aliases</a>
|
||||
<a href="#splats">Splats...</a>
|
||||
<a href="#while">While & Until Loops</a>
|
||||
<a href="#while">While, Until, and Loop</a>
|
||||
<a href="#comprehensions">Comprehensions (Arrays, Objects, and Ranges)</a>
|
||||
<a href="#slice_splice">Array Slicing and Splicing with Ranges</a>
|
||||
<a href="#expressions">Everything is an Expression</a>
|
||||
|
@ -110,8 +110,7 @@ alert reverse '.eeffoC yrT'</textarea></div>
|
|||
it compiles into clean JavaScript (the good parts) that can use existing
|
||||
JavaScript libraries seamlessly, and passes through
|
||||
<a href="http://www.jslint.com/">JSLint</a> without warnings. The compiled
|
||||
output is quite readable — pretty-printed, with comments
|
||||
preserved intact.
|
||||
output is pretty-printed and quite readable.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
@ -518,6 +517,16 @@ ages = {
|
|||
};
|
||||
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
|
||||
;alert(song.join(","));'>run: song.join(",")</button><br class='clear' /></div>
|
||||
<p>
|
||||
In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties
|
||||
of an object, without quoting them as strings. CoffeeScript notices and quotes
|
||||
them for you, so you don't have to worry about it (say, when using jQuery).
|
||||
</p>
|
||||
<div class='code'><pre class="idle">$(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).css {class<span class="Keyword">:</span> <span class="String"><span class="String">'</span>active<span class="String">'</span></span>}
|
||||
</pre><pre class="idle"><span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).css({
|
||||
<span class="String"><span class="String">'</span>class<span class="String">'</span></span>: <span class="String"><span class="String">'</span>active<span class="String">'</span></span>
|
||||
});
|
||||
</pre><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<span id="lexical_scope" class="bookmark"></span>
|
||||
|
@ -650,6 +659,10 @@ options <span class="Keyword">=</span> options <span class="Keyword">||</span> d
|
|||
<p>
|
||||
As a shortcut for <tt>this.property</tt>, you can use <tt>@property</tt>.
|
||||
</p>
|
||||
<p>
|
||||
You can use <tt>in</tt> to test for array presence, and <tt>of</tt> to
|
||||
test for JavaScript object-key presence.
|
||||
</p>
|
||||
<div class='code'><pre class="idle">launch() <span class="Keyword">if</span> ignition <span class="Keyword">is</span> <span class="BuiltInConstant">on</span>
|
||||
|
||||
volume<span class="Keyword">:</span> <span class="Number">10</span> <span class="Keyword">if</span> band <span class="Keyword">isnt</span> SpinalTap
|
||||
|
@ -658,8 +671,10 @@ letTheWildRumpusBegin() <span class="Keyword">unless</span> answer <span class="
|
|||
|
||||
<span class="Keyword">if</span> car.speed <span class="Keyword"><</span> limit <span class="Keyword">then</span> accelerate()
|
||||
|
||||
winner<span class="Keyword">:</span> <span class="BuiltInConstant">yes</span> <span class="Keyword">if</span> pick <span class="Keyword">in</span> [<span class="Number">47</span>, <span class="Number">92</span>, <span class="Number">13</span>]
|
||||
|
||||
print <span class="String"><span class="String">"</span>My name is <span class="String">"</span></span> <span class="Keyword">+</span> <span class="Variable">@name</span>
|
||||
</pre><pre class="idle"><span class="Storage">var</span> volume;
|
||||
</pre><pre class="idle"><span class="Storage">var</span> volume, winner;
|
||||
<span class="Keyword">if</span> (ignition <span class="Keyword">===</span> <span class="BuiltInConstant">true</span>) {
|
||||
launch();
|
||||
}
|
||||
|
@ -670,6 +685,9 @@ print <span class="String"><span class="String">"</span>My name is <span cl
|
|||
letTheWildRumpusBegin();
|
||||
}
|
||||
car.speed <span class="Keyword"><</span> limit ? accelerate() : <span class="BuiltInConstant">null</span>;
|
||||
<span class="Keyword">if</span> (<span class="Number">47</span> <span class="Keyword">===</span> pick <span class="Keyword">||</span> <span class="Number">92</span> <span class="Keyword">===</span> pick <span class="Keyword">||</span> <span class="Number">13</span> <span class="Keyword">===</span> pick) {
|
||||
winner <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
|
||||
}
|
||||
<span class="LibraryFunction">print</span>(<span class="String"><span class="String">"</span>My name is <span class="String">"</span></span> <span class="Keyword">+</span> <span class="Variable">this</span>.<span class="LibraryConstant">name</span>);
|
||||
</pre><br class='clear' /></div>
|
||||
|
||||
|
@ -742,7 +760,7 @@ alert("The Field: " + rest);
|
|||
|
||||
<p>
|
||||
<span id="while" class="bookmark"></span>
|
||||
<b class="header">While & Until Loops</b>
|
||||
<b class="header">While, Until, and Loop</b>
|
||||
The only low-level loop that CoffeeScript provides is the <b>while</b> loop. The
|
||||
main difference from JavaScript is that the <b>while</b> loop can be used
|
||||
as an expression, returning an array containing the result of each iteration
|
||||
|
@ -755,7 +773,7 @@ alert("The Field: " + rest);
|
|||
|
||||
<span class="Comment"><span class="Comment">#</span> Nursery Rhyme</span>
|
||||
num<span class="Keyword">:</span> <span class="Number">6</span>
|
||||
lyrics<span class="Keyword">:</span> <span class="Keyword">while</span> num <span class="Keyword">-</span><span class="Keyword">=</span> <span class="Number">1</span>
|
||||
lyrics<span class="Keyword">:</span> <span class="Keyword">while</span> num<span class="Keyword">:</span> <span class="Keyword">-</span> <span class="Number">1</span>
|
||||
num <span class="Keyword">+</span> <span class="String"><span class="String">"</span> little monkeys, jumping on the bed.</span>
|
||||
<span class="String"> One fell out and bumped his head.<span class="String">"</span></span>
|
||||
</pre><pre class="idle"><span class="Storage">var</span> _a, lyrics, num;
|
||||
|
@ -796,9 +814,10 @@ One fell out and bumped his head.");
|
|||
})();
|
||||
;alert(lyrics.join("\n"));'>run: lyrics.join("\n")</button><br class='clear' /></div>
|
||||
<p>
|
||||
For readability, the <b>until</b> loop serves as an inverted <b>while</b> loop.
|
||||
For readability, the <b>until</b> keyword is equivalent to <tt>while not</tt>,
|
||||
and the <b>loop</b> keyword is equivalent to <tt>while true</tt>.
|
||||
Other JavaScript loops, such as <b>for</b> loops and <b>do-while</b> loops
|
||||
can be mimicked by variations on <b>while</b>, but the hope is that you
|
||||
can be mimicked by variations on <b>loop</b>, but the hope is that you
|
||||
won't need to do that with CoffeeScript, either because you're using
|
||||
<b>each</b> (<b>forEach</b>) style iterators, or...
|
||||
</p>
|
||||
|
@ -1800,6 +1819,11 @@ html <span class="Keyword">=</span> <span class="String"><span class="String">'<
|
|||
— a custom filter for rendering CoffeeScript inline within
|
||||
<a href="http://haml-lang.com/">HAML</a> templates.
|
||||
</li>
|
||||
<li>
|
||||
<b>jashkenas</b>'s <a href="http://jashkenas.github.com/docco/">Docco</a>
|
||||
— A quick-and-dirty literate-programming-style documentation generator
|
||||
for CoffeeScript. Used to produce the annotated source.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>
|
||||
|
@ -1821,6 +1845,23 @@ html <span class="Keyword">=</span> <span class="String"><span class="String">'<
|
|||
<span id="change_log" class="bookmark"></span>
|
||||
Change Log
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
<b class="header" style="margin-top: 20px;">0.7.0</b>
|
||||
Official CoffeeScript variable style is now camelCase, as in JavaScript.
|
||||
Reserved words are now allowed as object keys, and will be quoted for you.
|
||||
Range comprehensions now generate cleaner code, but you have to specify <tt>by -1</tt>
|
||||
if you'd like to iterate downward. Reporting of syntax errors is greatly
|
||||
improved from the previous release. Running <tt>coffee</tt> with no arguments
|
||||
now launches the REPL, with Readline support. The <tt>&-</tt> bind operator
|
||||
has been removed from CoffeeScript. The <tt>loop</tt> keyword was added,
|
||||
which is equivalent to a <tt>while true</tt> loop. Comprehensions that contain
|
||||
closures will now close over their variables, like the semantics of a <tt>forEach</tt>.
|
||||
You can now use bound function in class definitions (bound to the instance).
|
||||
For consistency, <tt>a in b</tt> is now an array presence check, and <tt>a of b</tt>
|
||||
is an object-key check. Comments are no longer passed through to the generated
|
||||
JavaScript.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b class="header" style="margin-top: 20px;">0.6.2</b>
|
||||
|
|
Loading…
Reference in New Issue