mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
more additions to the documentation for 0.9.0
This commit is contained in:
parent
b42045f3f7
commit
f43c79c101
8 changed files with 264 additions and 265 deletions
|
@ -1,2 +0,0 @@
|
||||||
greeting = "Hello CoffeeScript"
|
|
||||||
difficulty = 0.5
|
|
|
@ -2,13 +2,16 @@ song = ["do", "re", "mi", "fa", "so"]
|
||||||
|
|
||||||
singers = {Jagger: 'Rock', Elvis: 'Roll'}
|
singers = {Jagger: 'Rock', Elvis: 'Roll'}
|
||||||
|
|
||||||
ages =
|
|
||||||
max: 10
|
|
||||||
ida: 9
|
|
||||||
tim: 11
|
|
||||||
|
|
||||||
matrix = [
|
matrix = [
|
||||||
1, 0, 1
|
1, 0, 1
|
||||||
0, 0, 1
|
0, 0, 1
|
||||||
1, 1, 0
|
1, 1, 0
|
||||||
]
|
]
|
||||||
|
|
||||||
|
kids =
|
||||||
|
brother:
|
||||||
|
name: 'Max'
|
||||||
|
age: 11
|
||||||
|
sister:
|
||||||
|
name: 'Ida'
|
||||||
|
age: 9
|
|
@ -1,8 +1,8 @@
|
||||||
body {
|
body {
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
color: #191933;
|
color: #191933;
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif !important;
|
||||||
}
|
}
|
||||||
div.container {
|
div.container {
|
||||||
width: 950px;
|
width: 950px;
|
||||||
|
@ -131,13 +131,15 @@ div.code {
|
||||||
background: #fdcdcc;
|
background: #fdcdcc;
|
||||||
color: #864544;
|
color: #864544;
|
||||||
border: 1px solid #864544;
|
border: 1px solid #864544;
|
||||||
font: 10px/15px Arial;
|
font-size: 10px;
|
||||||
|
line-height: 15px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
.navigation {
|
.navigation {
|
||||||
height: 50px;
|
height: 50px;
|
||||||
font: bold 11px/50px Arial;
|
font-size: 11px;
|
||||||
|
line-height: 50px;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
position: relative;
|
position: relative;
|
||||||
float: left;
|
float: left;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -39,7 +39,6 @@
|
||||||
<a href="#language">Language Reference</a>
|
<a href="#language">Language Reference</a>
|
||||||
<a href="#whitespace">Significant Whitespace</a>
|
<a href="#whitespace">Significant Whitespace</a>
|
||||||
<a href="#functions">Functions and Invocation</a>
|
<a href="#functions">Functions and Invocation</a>
|
||||||
<a href="#assignment">Assignment</a>
|
|
||||||
<a href="#objects_and_arrays">Objects and Arrays</a>
|
<a href="#objects_and_arrays">Objects and Arrays</a>
|
||||||
<a href="#lexical_scope">Lexical Scoping and Variable Safety</a>
|
<a href="#lexical_scope">Lexical Scoping and Variable Safety</a>
|
||||||
<a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
|
<a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
|
||||||
|
@ -164,13 +163,12 @@ alert reverse '.eeffoC yrT'</textarea></div>
|
||||||
on top of the <a href="http://github.com/zaach/jison">Jison parser generator</a>, and is available
|
on top of the <a href="http://github.com/zaach/jison">Jison parser generator</a>, and is available
|
||||||
as a <a href="http://nodejs.org/">Node.js</a> utility. The core compiler however,
|
as a <a href="http://nodejs.org/">Node.js</a> utility. The core compiler however,
|
||||||
does not depend on Node, and can be run in other server-side-JavaScript environments,
|
does not depend on Node, and can be run in other server-side-JavaScript environments,
|
||||||
or in the browser (see "Try CoffeeScript", above). This may be helpful,
|
or in the browser (see "Try CoffeeScript", above).
|
||||||
as Node only run on flavors of nix, and not Windows, for the time being.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To install, first make sure you have a working copy of the latest tagged version of
|
To install, first make sure you have a working copy of the latest tagged version of
|
||||||
<a href="http://nodejs.org/">Node.js</a>, currently <b>0.1.90</b> or higher.
|
<a href="http://nodejs.org/">Node.js</a>, currently <b>0.1.102</b> or higher.
|
||||||
Then clone the CoffeeScript
|
Then clone the CoffeeScript
|
||||||
<a href="http://github.com/jashkenas/coffee-script">source repository</a>
|
<a href="http://github.com/jashkenas/coffee-script">source repository</a>
|
||||||
from GitHub, or download the latest
|
from GitHub, or download the latest
|
||||||
|
@ -244,7 +242,7 @@ sudo npm install coffee-script</pre>
|
||||||
(<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
|
(<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
|
||||||
command is installed, use it
|
command is installed, use it
|
||||||
to check the compilation of a CoffeeScript file. (Handy in
|
to check the compilation of a CoffeeScript file. (Handy in
|
||||||
conjunction with <tt>--watch</tt>)
|
conjunction with <br /> <tt>--watch</tt>)
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -356,34 +354,14 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
||||||
function body. The empty function looks like this: <tt>-></tt>
|
function body. The empty function looks like this: <tt>-></tt>
|
||||||
</p>
|
</p>
|
||||||
<%= code_for('functions', 'cube(5)') %>
|
<%= code_for('functions', 'cube(5)') %>
|
||||||
<p>
|
|
||||||
If you'd like to assign a function literal to a variable, but not have
|
|
||||||
it be named, just wrap the function definition in parentheses:
|
|
||||||
<tt>((x) -> x * x)</tt>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<span id="assignment" class="bookmark"></span>
|
|
||||||
<b class="header">Assignment</b>
|
|
||||||
Use a colon <tt>:</tt> to assign, as in
|
|
||||||
<a href="http://json.org">JSON</a>. Equal signs are only needed for
|
|
||||||
mathy things. While colons are preferred, the two may be used interchangeably,
|
|
||||||
even within object literals.
|
|
||||||
</p>
|
|
||||||
<%= code_for('assignment', 'greeting') %>
|
|
||||||
<p>
|
|
||||||
All declaration of new variables is pushed up to the top of the nearest
|
|
||||||
lexical scope, so that assignment may always be performed within expressions.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span id="objects_and_arrays" class="bookmark"></span>
|
<span id="objects_and_arrays" class="bookmark"></span>
|
||||||
<b class="header">Objects and Arrays</b>
|
<b class="header">Objects and Arrays</b>
|
||||||
Object and Array literals look very similar to their JavaScript cousins.
|
Object and Array literals look very similar to their JavaScript cousins.
|
||||||
When you spread out each assignment on a separate line, the commas are
|
When you spread out each property on a separate line, the commas are
|
||||||
optional. In this way, assigning object properties looks the same as
|
optional. Implicit objects may be created with indentation instead of
|
||||||
assigning local variables, and can be moved around freely. Feel free to mix
|
brackets, winding up looking quite similar to YAML.
|
||||||
and match the two styles.
|
|
||||||
</p>
|
</p>
|
||||||
<%= code_for('objects_and_arrays', 'song.join(",")') %>
|
<%= code_for('objects_and_arrays', 'song.join(",")') %>
|
||||||
<p>
|
<p>
|
||||||
|
@ -426,7 +404,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
||||||
<p>
|
<p>
|
||||||
If you'd like to create top-level variables for other scripts to use,
|
If you'd like to create top-level variables for other scripts to use,
|
||||||
attach them as properties on <b>window</b>, or on the <b>exports</b>
|
attach them as properties on <b>window</b>, or on the <b>exports</b>
|
||||||
object in CommonJS. The <b>existential operator</b> (below), gives you a
|
object in CommonJS. The <b>existential operator</b> (covered below), gives you a
|
||||||
reliable way to figure out where to add them, if you're targeting both
|
reliable way to figure out where to add them, if you're targeting both
|
||||||
CommonJS and the browser: <tt>root: exports ? this</tt>
|
CommonJS and the browser: <tt>root: exports ? this</tt>
|
||||||
</p>
|
</p>
|
||||||
|
@ -446,11 +424,6 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
||||||
a regular <b>if</b> statement inline.
|
a regular <b>if</b> statement inline.
|
||||||
</p>
|
</p>
|
||||||
<%= code_for('conditionals') %>
|
<%= code_for('conditionals') %>
|
||||||
<p>
|
|
||||||
You can assign a variable to a half-expression to perform an operation
|
|
||||||
like Ruby's <tt>||=</tt>, which only assigns a value to a variable
|
|
||||||
if the variable's current value is falsy.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span id="aliases" class="bookmark"></span>
|
<span id="aliases" class="bookmark"></span>
|
||||||
|
@ -959,6 +932,27 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
||||||
Change Log
|
Change Log
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b class="header" style="margin-top: 20px;">0.9.0</b>
|
||||||
|
The CoffeeScript <b>0.9</b> series is considered to be a release candidate
|
||||||
|
for <b>1.0</b>; let's give her a shakedown cruise. <b>0.9.0</b> introduces a massive
|
||||||
|
backwards-incompatible change: Assignment now uses <tt>=</tt>, and object
|
||||||
|
literals use <tt>:</tt>, as in JavaScript. This allows us to have implicit
|
||||||
|
object literals, and YAML-style object definitions. Half assignments are
|
||||||
|
removed, in favor of <tt>+=</tt>, <tt>or=</tt>, and friends.
|
||||||
|
Downwards range comprehensions are now safe again, and are optimized to
|
||||||
|
straight for loops when created with integer endpoints.
|
||||||
|
A fast, unguarded form of object comprehension was added:
|
||||||
|
<tt>for all key, value of object</tt>. Mentioning the <tt>super</tt> keyword
|
||||||
|
with no arguments now forwards all arguments passed to the function,
|
||||||
|
as in Ruby. If you extend class <tt>B</tt> from parent class <tt>A</tt>, if
|
||||||
|
<tt>A</tt> has an <tt>extended</tt> method defined, it will be called, passing in <tt>B</tt> —
|
||||||
|
this enables static inheritance, among other things. Cleaner output for
|
||||||
|
functions bound with the fat arrow. <tt>@variables</tt> can now be used
|
||||||
|
in parameter lists, with the parameter being automatically set as a property
|
||||||
|
on the object — useful in constructors and setter functions.
|
||||||
|
Constructor functions can now take splats.
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b class="header" style="margin-top: 20px;">0.7.2</b>
|
<b class="header" style="margin-top: 20px;">0.7.2</b>
|
||||||
Quick bugfix (right after 0.7.1) for a problem that prevented <tt>coffee</tt>
|
Quick bugfix (right after 0.7.1) for a problem that prevented <tt>coffee</tt>
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
var difficulty, greeting;
|
|
||||||
greeting = "Hello CoffeeScript";
|
|
||||||
difficulty = 0.5;
|
|
|
@ -1,12 +1,17 @@
|
||||||
var ages, matrix, singers, song;
|
var kids, matrix, singers, song;
|
||||||
song = ["do", "re", "mi", "fa", "so"];
|
song = ["do", "re", "mi", "fa", "so"];
|
||||||
singers = {
|
singers = {
|
||||||
Jagger: 'Rock',
|
Jagger: 'Rock',
|
||||||
Elvis: 'Roll'
|
Elvis: 'Roll'
|
||||||
};
|
};
|
||||||
ages = {
|
|
||||||
max: 10,
|
|
||||||
ida: 9,
|
|
||||||
tim: 11
|
|
||||||
};
|
|
||||||
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
|
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
|
||||||
|
kids = {
|
||||||
|
brother: {
|
||||||
|
name: 'Max',
|
||||||
|
age: 11
|
||||||
|
},
|
||||||
|
sister: {
|
||||||
|
name: 'Ida',
|
||||||
|
age: 9
|
||||||
|
}
|
||||||
|
};
|
118
index.html
118
index.html
|
@ -26,7 +26,6 @@
|
||||||
<a href="#language">Language Reference</a>
|
<a href="#language">Language Reference</a>
|
||||||
<a href="#whitespace">Significant Whitespace</a>
|
<a href="#whitespace">Significant Whitespace</a>
|
||||||
<a href="#functions">Functions and Invocation</a>
|
<a href="#functions">Functions and Invocation</a>
|
||||||
<a href="#assignment">Assignment</a>
|
|
||||||
<a href="#objects_and_arrays">Objects and Arrays</a>
|
<a href="#objects_and_arrays">Objects and Arrays</a>
|
||||||
<a href="#lexical_scope">Lexical Scoping and Variable Safety</a>
|
<a href="#lexical_scope">Lexical Scoping and Variable Safety</a>
|
||||||
<a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
|
<a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
|
||||||
|
@ -246,13 +245,12 @@ cubes = (function() {
|
||||||
on top of the <a href="http://github.com/zaach/jison">Jison parser generator</a>, and is available
|
on top of the <a href="http://github.com/zaach/jison">Jison parser generator</a>, and is available
|
||||||
as a <a href="http://nodejs.org/">Node.js</a> utility. The core compiler however,
|
as a <a href="http://nodejs.org/">Node.js</a> utility. The core compiler however,
|
||||||
does not depend on Node, and can be run in other server-side-JavaScript environments,
|
does not depend on Node, and can be run in other server-side-JavaScript environments,
|
||||||
or in the browser (see "Try CoffeeScript", above). This may be helpful,
|
or in the browser (see "Try CoffeeScript", above).
|
||||||
as Node only run on flavors of nix, and not Windows, for the time being.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To install, first make sure you have a working copy of the latest tagged version of
|
To install, first make sure you have a working copy of the latest tagged version of
|
||||||
<a href="http://nodejs.org/">Node.js</a>, currently <b>0.1.90</b> or higher.
|
<a href="http://nodejs.org/">Node.js</a>, currently <b>0.1.102</b> or higher.
|
||||||
Then clone the CoffeeScript
|
Then clone the CoffeeScript
|
||||||
<a href="http://github.com/jashkenas/coffee-script">source repository</a>
|
<a href="http://github.com/jashkenas/coffee-script">source repository</a>
|
||||||
from GitHub, or download the latest
|
from GitHub, or download the latest
|
||||||
|
@ -326,7 +324,7 @@ sudo npm install coffee-script</pre>
|
||||||
(<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
|
(<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
|
||||||
command is installed, use it
|
command is installed, use it
|
||||||
to check the compilation of a CoffeeScript file. (Handy in
|
to check the compilation of a CoffeeScript file. (Handy in
|
||||||
conjunction with <tt>--watch</tt>)
|
conjunction with <br /> <tt>--watch</tt>)
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -453,80 +451,66 @@ square = function(x) {
|
||||||
cube = function(x) {
|
cube = function(x) {
|
||||||
return square(x) * x;
|
return square(x) * x;
|
||||||
};;alert(cube(5));'>run: cube(5)</button><br class='clear' /></div>
|
};;alert(cube(5));'>run: cube(5)</button><br class='clear' /></div>
|
||||||
<p>
|
|
||||||
If you'd like to assign a function literal to a variable, but not have
|
|
||||||
it be named, just wrap the function definition in parentheses:
|
|
||||||
<tt>((x) -> x * x)</tt>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<span id="assignment" class="bookmark"></span>
|
|
||||||
<b class="header">Assignment</b>
|
|
||||||
Use a colon <tt>:</tt> to assign, as in
|
|
||||||
<a href="http://json.org">JSON</a>. Equal signs are only needed for
|
|
||||||
mathy things. While colons are preferred, the two may be used interchangeably,
|
|
||||||
even within object literals.
|
|
||||||
</p>
|
|
||||||
<div class='code'><pre class="idle">greeting <span class="Keyword">=</span> <span class="String"><span class="String">"</span>Hello CoffeeScript<span class="String">"</span></span>
|
|
||||||
difficulty <span class="Keyword">=</span> <span class="Number">0.5</span>
|
|
||||||
</pre><pre class="idle"><span class="Storage">var</span> difficulty, greeting;
|
|
||||||
greeting <span class="Keyword">=</span> <span class="String"><span class="String">"</span>Hello CoffeeScript<span class="String">"</span></span>;
|
|
||||||
difficulty <span class="Keyword">=</span> <span class="Number">0.5</span>;
|
|
||||||
</pre><button onclick='javascript: var difficulty, greeting;
|
|
||||||
greeting = "Hello CoffeeScript";
|
|
||||||
difficulty = 0.5;;alert(greeting);'>run: greeting</button><br class='clear' /></div>
|
|
||||||
<p>
|
|
||||||
All declaration of new variables is pushed up to the top of the nearest
|
|
||||||
lexical scope, so that assignment may always be performed within expressions.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span id="objects_and_arrays" class="bookmark"></span>
|
<span id="objects_and_arrays" class="bookmark"></span>
|
||||||
<b class="header">Objects and Arrays</b>
|
<b class="header">Objects and Arrays</b>
|
||||||
Object and Array literals look very similar to their JavaScript cousins.
|
Object and Array literals look very similar to their JavaScript cousins.
|
||||||
When you spread out each assignment on a separate line, the commas are
|
When you spread out each property on a separate line, the commas are
|
||||||
optional. In this way, assigning object properties looks the same as
|
optional. Implicit objects may be created with indentation instead of
|
||||||
assigning local variables, and can be moved around freely. Feel free to mix
|
brackets, winding up looking quite similar to YAML.
|
||||||
and match the two styles.
|
|
||||||
</p>
|
</p>
|
||||||
<div class='code'><pre class="idle">song <span class="Keyword">=</span> [<span class="String"><span class="String">"</span>do<span class="String">"</span></span>, <span class="String"><span class="String">"</span>re<span class="String">"</span></span>, <span class="String"><span class="String">"</span>mi<span class="String">"</span></span>, <span class="String"><span class="String">"</span>fa<span class="String">"</span></span>, <span class="String"><span class="String">"</span>so<span class="String">"</span></span>]
|
<div class='code'><pre class="idle">song <span class="Keyword">=</span> [<span class="String"><span class="String">"</span>do<span class="String">"</span></span>, <span class="String"><span class="String">"</span>re<span class="String">"</span></span>, <span class="String"><span class="String">"</span>mi<span class="String">"</span></span>, <span class="String"><span class="String">"</span>fa<span class="String">"</span></span>, <span class="String"><span class="String">"</span>so<span class="String">"</span></span>]
|
||||||
|
|
||||||
singers <span class="Keyword">=</span> {Jagger<span class="Keyword">:</span> <span class="String"><span class="String">'</span>Rock<span class="String">'</span></span>, Elvis<span class="Keyword">:</span> <span class="String"><span class="String">'</span>Roll<span class="String">'</span></span>}
|
singers <span class="Keyword">=</span> {Jagger<span class="Keyword">:</span> <span class="String"><span class="String">'</span>Rock<span class="String">'</span></span>, Elvis<span class="Keyword">:</span> <span class="String"><span class="String">'</span>Roll<span class="String">'</span></span>}
|
||||||
|
|
||||||
ages <span class="Keyword">=</span>
|
|
||||||
max<span class="Keyword">:</span> <span class="Number">10</span>
|
|
||||||
ida<span class="Keyword">:</span> <span class="Number">9</span>
|
|
||||||
tim<span class="Keyword">:</span> <span class="Number">11</span>
|
|
||||||
|
|
||||||
matrix <span class="Keyword">=</span> [
|
matrix <span class="Keyword">=</span> [
|
||||||
<span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">1</span>
|
<span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">1</span>
|
||||||
<span class="Number">0</span>, <span class="Number">0</span>, <span class="Number">1</span>
|
<span class="Number">0</span>, <span class="Number">0</span>, <span class="Number">1</span>
|
||||||
<span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">0</span>
|
<span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">0</span>
|
||||||
]
|
]
|
||||||
</pre><pre class="idle"><span class="Storage">var</span> ages, matrix, singers, song;
|
|
||||||
|
kids <span class="Keyword">=</span>
|
||||||
|
brother<span class="Keyword">:</span>
|
||||||
|
name<span class="Keyword">:</span> <span class="String"><span class="String">'</span>Max<span class="String">'</span></span>
|
||||||
|
age<span class="Keyword">:</span> <span class="Number">11</span>
|
||||||
|
sister<span class="Keyword">:</span>
|
||||||
|
name<span class="Keyword">:</span> <span class="String"><span class="String">'</span>Ida<span class="String">'</span></span>
|
||||||
|
age<span class="Keyword">:</span> <span class="Number">9</span>
|
||||||
|
</pre><pre class="idle"><span class="Storage">var</span> kids, matrix, singers, song;
|
||||||
song <span class="Keyword">=</span> [<span class="String"><span class="String">"</span>do<span class="String">"</span></span>, <span class="String"><span class="String">"</span>re<span class="String">"</span></span>, <span class="String"><span class="String">"</span>mi<span class="String">"</span></span>, <span class="String"><span class="String">"</span>fa<span class="String">"</span></span>, <span class="String"><span class="String">"</span>so<span class="String">"</span></span>];
|
song <span class="Keyword">=</span> [<span class="String"><span class="String">"</span>do<span class="String">"</span></span>, <span class="String"><span class="String">"</span>re<span class="String">"</span></span>, <span class="String"><span class="String">"</span>mi<span class="String">"</span></span>, <span class="String"><span class="String">"</span>fa<span class="String">"</span></span>, <span class="String"><span class="String">"</span>so<span class="String">"</span></span>];
|
||||||
singers <span class="Keyword">=</span> {
|
singers <span class="Keyword">=</span> {
|
||||||
Jagger: <span class="String"><span class="String">'</span>Rock<span class="String">'</span></span>,
|
Jagger: <span class="String"><span class="String">'</span>Rock<span class="String">'</span></span>,
|
||||||
Elvis: <span class="String"><span class="String">'</span>Roll<span class="String">'</span></span>
|
Elvis: <span class="String"><span class="String">'</span>Roll<span class="String">'</span></span>
|
||||||
};
|
};
|
||||||
ages <span class="Keyword">=</span> {
|
|
||||||
max: <span class="Number">10</span>,
|
|
||||||
ida: <span class="Number">9</span>,
|
|
||||||
tim: <span class="Number">11</span>
|
|
||||||
};
|
|
||||||
matrix <span class="Keyword">=</span> [<span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">0</span>];
|
matrix <span class="Keyword">=</span> [<span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">0</span>];
|
||||||
</pre><button onclick='javascript: var ages, matrix, singers, song;
|
kids <span class="Keyword">=</span> {
|
||||||
|
brother: {
|
||||||
|
name: <span class="String"><span class="String">'</span>Max<span class="String">'</span></span>,
|
||||||
|
age: <span class="Number">11</span>
|
||||||
|
},
|
||||||
|
sister: {
|
||||||
|
name: <span class="String"><span class="String">'</span>Ida<span class="String">'</span></span>,
|
||||||
|
age: <span class="Number">9</span>
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</pre><button onclick='javascript: var kids, matrix, singers, song;
|
||||||
song = ["do", "re", "mi", "fa", "so"];
|
song = ["do", "re", "mi", "fa", "so"];
|
||||||
singers = {
|
singers = {
|
||||||
Jagger: 'Rock',
|
Jagger: 'Rock',
|
||||||
Elvis: 'Roll'
|
Elvis: 'Roll'
|
||||||
};
|
};
|
||||||
ages = {
|
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
|
||||||
max: 10,
|
kids = {
|
||||||
ida: 9,
|
brother: {
|
||||||
tim: 11
|
name: 'Max',
|
||||||
};
|
age: 11
|
||||||
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];;alert(song.join(","));'>run: song.join(",")</button><br class='clear' /></div>
|
},
|
||||||
|
sister: {
|
||||||
|
name: 'Ida',
|
||||||
|
age: 9
|
||||||
|
}
|
||||||
|
};;alert(song.join(","));'>run: song.join(",")</button><br class='clear' /></div>
|
||||||
<p>
|
<p>
|
||||||
In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties
|
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
|
of an object, without quoting them as strings. CoffeeScript notices and quotes
|
||||||
|
@ -591,7 +575,7 @@ inner = changeNumbers();;alert(inner);'>run: inner</button><br class='clear' /><
|
||||||
<p>
|
<p>
|
||||||
If you'd like to create top-level variables for other scripts to use,
|
If you'd like to create top-level variables for other scripts to use,
|
||||||
attach them as properties on <b>window</b>, or on the <b>exports</b>
|
attach them as properties on <b>window</b>, or on the <b>exports</b>
|
||||||
object in CommonJS. The <b>existential operator</b> (below), gives you a
|
object in CommonJS. The <b>existential operator</b> (covered below), gives you a
|
||||||
reliable way to figure out where to add them, if you're targeting both
|
reliable way to figure out where to add them, if you're targeting both
|
||||||
CommonJS and the browser: <tt>root: exports ? this</tt>
|
CommonJS and the browser: <tt>root: exports ? this</tt>
|
||||||
</p>
|
</p>
|
||||||
|
@ -634,11 +618,6 @@ options <span class="Keyword">or</span><span class="Keyword">=</span> defaults
|
||||||
date <span class="Keyword">=</span> friday ? sue : jill;
|
date <span class="Keyword">=</span> friday ? sue : jill;
|
||||||
options <span class="Keyword">=</span> options <span class="Keyword">||</span> defaults;
|
options <span class="Keyword">=</span> options <span class="Keyword">||</span> defaults;
|
||||||
</pre><br class='clear' /></div>
|
</pre><br class='clear' /></div>
|
||||||
<p>
|
|
||||||
You can assign a variable to a half-expression to perform an operation
|
|
||||||
like Ruby's <tt>||=</tt>, which only assigns a value to a variable
|
|
||||||
if the variable's current value is falsy.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span id="aliases" class="bookmark"></span>
|
<span id="aliases" class="bookmark"></span>
|
||||||
|
@ -1852,6 +1831,27 @@ task(<span class="String"><span class="String">'</span>build:parser<span class="
|
||||||
Change Log
|
Change Log
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b class="header" style="margin-top: 20px;">0.9.0</b>
|
||||||
|
The CoffeeScript <b>0.9</b> series is considered to be a release candidate
|
||||||
|
for <b>1.0</b>; let's give her a shakedown cruise. <b>0.9.0</b> introduces a massive
|
||||||
|
backwards-incompatible change: Assignment now uses <tt>=</tt>, and object
|
||||||
|
literals use <tt>:</tt>, as in JavaScript. This allows us to have implicit
|
||||||
|
object literals, and YAML-style object definitions. Half assignments are
|
||||||
|
removed, in favor of <tt>+=</tt>, <tt>or=</tt>, and friends.
|
||||||
|
Downwards range comprehensions are now safe again, and are optimized to
|
||||||
|
straight for loops when created with integer endpoints.
|
||||||
|
A fast, unguarded form of object comprehension was added:
|
||||||
|
<tt>for all key, value of object</tt>. Mentioning the <tt>super</tt> keyword
|
||||||
|
with no arguments now forwards all arguments passed to the function,
|
||||||
|
as in Ruby. If you extend class <tt>B</tt> from parent class <tt>A</tt>, if
|
||||||
|
<tt>A</tt> has an <tt>extended</tt> method defined, it will be called, passing in <tt>B</tt> —
|
||||||
|
this enables static inheritance, among other things. Cleaner output for
|
||||||
|
functions bound with the fat arrow. <tt>@variables</tt> can now be used
|
||||||
|
in parameter lists, with the parameter being automatically set as a property
|
||||||
|
on the object — useful in constructors and setter functions.
|
||||||
|
Constructor functions can now take splats.
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b class="header" style="margin-top: 20px;">0.7.2</b>
|
<b class="header" style="margin-top: 20px;">0.7.2</b>
|
||||||
Quick bugfix (right after 0.7.1) for a problem that prevented <tt>coffee</tt>
|
Quick bugfix (right after 0.7.1) for a problem that prevented <tt>coffee</tt>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue