aboutsummaryrefslogtreecommitdiff
path: root/tools/eliminator/node_modules/coffee-script/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eliminator/node_modules/coffee-script/index.html')
-rw-r--r--tools/eliminator/node_modules/coffee-script/index.html3028
1 files changed, 0 insertions, 3028 deletions
diff --git a/tools/eliminator/node_modules/coffee-script/index.html b/tools/eliminator/node_modules/coffee-script/index.html
deleted file mode 100644
index 5f1276d3..00000000
--- a/tools/eliminator/node_modules/coffee-script/index.html
+++ /dev/null
@@ -1,3028 +0,0 @@
-
-
-
-<!DOCTYPE html>
-<html>
-<head>
- <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
- <title>CoffeeScript</title>
- <link rel="canonical" href="http://coffeescript.org" />
- <link rel="stylesheet" type="text/css" href="documentation/css/docs.css" />
- <link rel="stylesheet" type="text/css" href="documentation/css/idle.css" />
- <link rel="shortcut icon" href="documentation/images/favicon.ico" />
-</head>
-<body>
-
- <div id="fadeout"></div>
-
- <div id="flybar">
- <a id="logo" href="#top"> </a>
- <div class="navigation toc">
- <div class="button">
- Table of Contents
- </div>
- <div class="contents menu">
- <a href="#overview">Overview</a>
- <a href="#installation">Installation</a>
- <a href="#usage">Usage</a>
- <a href="#language">Language Reference</a>
- <a href="#literals">Literals: Functions, Objects and Arrays</a>
- <a href="#lexical_scope">Lexical Scoping and Variable Safety</a>
- <a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
- <a href="#splats">Splats...</a>
- <a href="#loops">Loops and Comprehensions</a>
- <a href="#slices">Array Slicing and Splicing</a>
- <a href="#expressions">Everything is an Expression</a>
- <a href="#operators">Operators and Aliases</a>
- <a href="#classes">Classes, Inheritance, and Super</a>
- <a href="#destructuring">Destructuring Assignment</a>
- <a href="#fat_arrow">Function Binding</a>
- <a href="#embedded">Embedded JavaScript</a>
- <a href="#switch">Switch and Try/Catch</a>
- <a href="#comparisons">Chained Comparisons</a>
- <a href="#strings">String Interpolation, Block Strings, and Block Comments</a>
- <a href="#regexes">Block Regular Expressions</a>
- <a href="#cake">Cake, and Cakefiles</a>
- <a href="#scripts">"text/coffeescript" Script Tags</a>
- <a href="#resources">Books, Screencasts, Examples and Resources</a>
- <a href="#changelog">Change Log</a>
- </div>
- </div>
- <div class="navigation try">
- <div class="button">
- Try CoffeeScript
- <div class="repl_bridge"></div>
- </div>
- <div class="contents repl_wrapper">
- <div class="code">
- <div class="screenshadow tl"></div>
- <div class="screenshadow tr"></div>
- <div class="screenshadow bl"></div>
- <div class="screenshadow br"></div>
- <div id="repl_source_wrap">
- <textarea id="repl_source" rows="100" spellcheck="false">alert "Hello CoffeeScript!"</textarea>
- </div>
- <div id="repl_results_wrap"><pre id="repl_results"></pre></div>
- <div class="minibutton dark run" title="Ctrl-Enter">Run</div>
- <a class="minibutton permalink" id="repl_permalink">Link</a>
- <br class="clear" />
- </div>
- </div>
- </div>
- <div class="navigation annotated">
- <div class="button">
- Annotated Source
- </div>
- <div class="contents menu">
- <a href="documentation/docs/grammar.html">Grammar Rules &mdash; src/grammar</a>
- <a href="documentation/docs/lexer.html">Lexing Tokens &mdash; src/lexer</a>
- <a href="documentation/docs/rewriter.html">The Rewriter &mdash; src/rewriter</a>
- <a href="documentation/docs/nodes.html">The Syntax Tree &mdash; src/nodes</a>
- <a href="documentation/docs/scope.html">Lexical Scope &mdash; src/scope</a>
- <a href="documentation/docs/helpers.html">Helpers &amp; Utility Functions &mdash; src/helpers</a>
- <a href="documentation/docs/coffee-script.html">The CoffeeScript Module &mdash; src/coffee-script</a>
- <a href="documentation/docs/cake.html">Cake &amp; Cakefiles &mdash; src/cake</a>
- <a href="documentation/docs/command.html">"coffee" Command-Line Utility &mdash; src/command</a>
- <a href="documentation/docs/optparse.html">Option Parsing &mdash; src/optparse</a>
- <a href="documentation/docs/repl.html">Interactive REPL &mdash; src/repl</a>
- </div>
- </div>
- <div id="error" style="display:none;"></div>
- </div>
-
- <div class="container">
- <span class="bookmark" id="top"></span>
-
- <p>
- <b>CoffeeScript is a little language that compiles into JavaScript.</b> Underneath
- all those awkward braces and semicolons, JavaScript has always had
- a gorgeous object model at its heart. CoffeeScript is an attempt to expose
- the good parts of JavaScript in a simple way.
- </p>
-
- <p>
- The golden rule of CoffeeScript is: <i>"It's just JavaScript"</i>. The code
- compiles one-to-one into the equivalent JS, and there is
- no interpretation at runtime. You can use any existing JavaScript library
- seamlessly from CoffeeScript (and vice-versa). The compiled output is
- readable and pretty-printed, passes through
- <a href="http://www.javascriptlint.com/">JavaScript Lint</a>
- without warnings, will work in every JavaScript runtime, and tends
- to run as fast or faster than the equivalent handwritten JavaScript.
- </p>
-
- <p>
- <b>Latest Version:</b>
- <a href="http://github.com/jashkenas/coffee-script/tarball/1.3.3">1.3.3</a>
- </p>
-
- <h2>
- <span id="overview" class="bookmark"></span>
- Overview
- </h2>
-
- <p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p>
-
- <div class='code'><pre class="idle"><span class="Comment"><span class="Comment">#</span> Assignment:</span>
-number <span class="Keyword">=</span> <span class="Number">42</span>
-opposite <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>
-
-<span class="Comment"><span class="Comment">#</span> Conditions:</span>
-number <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">42</span> <span class="Keyword">if</span> opposite
-
-<span class="Comment"><span class="Comment">#</span> Functions:</span>
-<span class="FunctionName">square </span><span class="Keyword">=</span> <span class="FunctionArgument">(x)</span> <span class="Storage">-&gt;</span> x <span class="Keyword">*</span> x
-
-<span class="Comment"><span class="Comment">#</span> Arrays:</span>
-list <span class="Keyword">=</span> [<span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>]
-
-<span class="Comment"><span class="Comment">#</span> Objects:</span>
-math <span class="Keyword">=</span>
- root: Math.sqrt
- square: square
- <span class="FunctionName">cube</span><span class="Keyword">:</span> <span class="FunctionArgument">(x)</span> <span class="Storage">-&gt;</span> x <span class="Keyword">*</span> square x
-
-<span class="Comment"><span class="Comment">#</span> Splats:</span>
-<span class="FunctionName">race </span><span class="Keyword">=</span> <span class="FunctionArgument">(winner, runners...)</span> <span class="Storage">-&gt;</span>
- print winner, runners
-
-<span class="Comment"><span class="Comment">#</span> Existence:</span>
-alert <span class="String"><span class="String">&quot;</span>I knew it!<span class="String">&quot;</span></span> <span class="Keyword">if</span> elvis<span class="Keyword">?</span>
-
-<span class="Comment"><span class="Comment">#</span> Array comprehensions:</span>
-cubes <span class="Keyword">=</span> (math.cube num <span class="Keyword">for</span> num <span class="Keyword">in</span> list)
-</pre><pre class="idle"><span class="Storage">var</span> cubes, list, math, num, number, opposite, race, square,
- __slice <span class="Keyword">=</span> [].slice;
-
-number <span class="Keyword">=</span> <span class="Number">42</span>;
-
-opposite <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
-
-<span class="Keyword">if</span> (opposite) {
- number <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">42</span>;
-}
-
-<span class="FunctionName">square</span> = <span class="Storage">function</span>(<span class="FunctionArgument">x</span>) {
- <span class="Keyword">return</span> x <span class="Keyword">*</span> x;
-};
-
-list <span class="Keyword">=</span> [<span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>];
-
-math <span class="Keyword">=</span> {
- root: <span class="LibraryClassType">Math</span>.sqrt,
- square: square,
- <span class="FunctionName">cube</span>: <span class="Storage">function</span>(<span class="FunctionArgument">x</span>) {
- <span class="Keyword">return</span> x <span class="Keyword">*</span> square(x);
- }
-};
-
-<span class="FunctionName">race</span> = <span class="Storage">function</span>() {
- <span class="Storage">var</span> runners, winner;
- winner <span class="Keyword">=</span> arguments[<span class="Number">0</span>], runners <span class="Keyword">=</span> <span class="Number">2</span> <span class="Keyword">&lt;=</span> arguments.<span class="LibraryConstant">length</span> ? __slice.<span class="LibraryFunction">call</span>(arguments, <span class="Number">1</span>) : [];
- <span class="Keyword">return</span> <span class="LibraryFunction">print</span>(winner, runners);
-};
-
-<span class="Keyword">if</span> (<span class="Keyword">typeof</span> elvis <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">&quot;</span>undefined<span class="String">&quot;</span></span> <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> elvis <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) {
- <span class="LibraryFunction">alert</span>(<span class="String"><span class="String">&quot;</span>I knew it!<span class="String">&quot;</span></span>);
-}
-
-cubes <span class="Keyword">=</span> (<span class="Storage">function</span>() {
- <span class="Storage">var</span> _i, _len, _results;
- _results <span class="Keyword">=</span> [];
- <span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _len <span class="Keyword">=</span> list.<span class="LibraryConstant">length</span>; _i <span class="Keyword">&lt;</span> _len; _i<span class="Keyword">++</span>) {
- num <span class="Keyword">=</span> list[_i];
- _results.<span class="LibraryFunction">push</span>(math.cube(num));
- }
- <span class="Keyword">return</span> _results;
-})();
-</pre><script>window.example1 = "# Assignment:\nnumber = 42\nopposite = true\n\n# Conditions:\nnumber = -42 if opposite\n\n# Functions:\nsquare = (x) -> x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)\n\nalert cubes"</script><div class='minibutton ok' onclick='javascript: var cubes, list, math, num, number, opposite, race, square,
- __slice = [].slice;
-
-number = 42;
-
-opposite = true;
-
-if (opposite) {
- number = -42;
-}
-
-square = function(x) {
- return x * x;
-};
-
-list = [1, 2, 3, 4, 5];
-
-math = {
- root: Math.sqrt,
- square: square,
- cube: function(x) {
- return x * square(x);
- }
-};
-
-race = function() {
- var runners, winner;
- winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
- return print(winner, runners);
-};
-
-if (typeof elvis !== "undefined" && elvis !== null) {
- alert("I knew it!");
-}
-
-cubes = (function() {
- var _i, _len, _results;
- _results = [];
- for (_i = 0, _len = list.length; _i < _len; _i++) {
- num = list[_i];
- _results.push(math.cube(num));
- }
- return _results;
-})();
-;alert(cubes);'>run: cubes</div><br class='clear' /></div>
-
- <h2>
- <span id="installation" class="bookmark"></span>
- Installation
- </h2>
-
- <p>
- The CoffeeScript compiler is itself
- <a href="documentation/docs/grammar.html">written in CoffeeScript</a>,
- using the <a href="http://jison.org">Jison parser generator</a>. The
- command-line version of <tt>coffee</tt> is available as a
- <a href="http://nodejs.org/">Node.js</a> utility. The
- <a href="extras/coffee-script.js">core compiler</a> however, does not
- depend on Node, and can be run in any JavaScript environment, or in the
- browser (see "Try CoffeeScript", above).
- </p>
-
- <p>
- To install, first make sure you have a working copy of the latest stable version of
- <a href="http://nodejs.org/">Node.js</a>, and <a href="http://npmjs.org">npm</a>
- (the Node Package Manager). You can then install CoffeeScript with npm:
- </p>
-
- <pre>
-npm install -g coffee-script</pre>
-
- <p>
- (Leave off the <tt>-g</tt> if you don't wish to install globally.)
- </p>
-
- <p>
- If you'd prefer to install the latest <b>master</b> version of CoffeeScript, you
- can clone the CoffeeScript
- <a href="http://github.com/jashkenas/coffee-script">source repository</a>
- from GitHub, or download
- <a href="http://github.com/jashkenas/coffee-script/tarball/master">the source</a> directly.
- To install the lastest master CoffeeScript compiler with npm:
- </p>
-
-<pre>
-npm install -g http://github.com/jashkenas/coffee-script/tarball/master</pre>
-
- <p>
- Or, if you want to install to <tt>/usr/local</tt>, and don't want to use
- npm to manage it, open the <tt>coffee-script</tt> directory and run:
- </p>
-
- <pre>
-sudo bin/cake install</pre>
-
- <h2>
- <span id="usage" class="bookmark"></span>
- Usage
- </h2>
-
- <p>
- Once installed, you should have access to the <tt>coffee</tt> command,
- which can execute scripts, compile <tt>.coffee</tt> files into <tt>.js</tt>,
- and provide an interactive REPL. The <tt>coffee</tt> command takes the
- following options:
- </p>
-
- <table>
- <tr>
- <td><code>-c, --compile</code></td>
- <td>
- Compile a <tt>.coffee</tt> script into a <tt>.js</tt> JavaScript file
- of the same name.
- </td>
- </tr>
- <tr>
- <td width="25%"><code>-i, --interactive</code></td>
- <td>
- Launch an interactive CoffeeScript session to try short snippets.
- Identical to calling <tt>coffee</tt> with no arguments.
- </td>
- </tr>
- <tr>
- <td><code>-o, --output [DIR]</code></td>
- <td>
- Write out all compiled JavaScript files into the specified directory.
- Use in conjunction with <tt>--compile</tt> or <tt>--watch</tt>.
- </td>
- </tr>
- <tr>
- <td><code>-j, --join [FILE]</code></td>
- <td>
- Before compiling, concatenate all scripts together in the order they
- were passed, and write them into the specified file.
- Useful for building large projects.
- </td>
- </tr>
- <tr>
- <td><code>-w, --watch</code></td>
- <td>
- Watch files for changes, rerunning the specified command when any
- file is updated.
- </td>
- </tr>
- <tr>
- <td><code>-p, --print</code></td>
- <td>
- Instead of writing out the JavaScript as a file, print it
- directly to <b>stdout</b>.
- </td>
- </tr>
- <tr>
- <td><code>-l, --lint</code></td>
- <td>
- If the <tt>jsl</tt>
- (<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
- command is installed, use it
- to check the compilation of a CoffeeScript file. (Handy in
- conjunction with <br /> <tt>--watch</tt>)
- </td>
- </tr>
- <tr>
- <td><code>-s, --stdio</code></td>
- <td>
- Pipe in CoffeeScript to STDIN and get back JavaScript over STDOUT.
- Good for use with processes written in other languages. An example:<br />
- <tt>cat src/cake.coffee | coffee -sc</tt>
- </td>
- </tr>
- <tr>
- <td><code>-e, --eval</code></td>
- <td>
- Compile and print a little snippet of CoffeeScript directly from the
- command line. For example:<br /><tt>coffee -e "console.log num for num in [10..1]"</tt>
- </td>
- </tr>
- <tr>
- <td><code>-r, --require</code></td>
- <td>
- Load a library before compiling or executing your script. Can be used
- to hook in to the compiler (to add Growl notifications, for example).
- </td>
- </tr>
- <tr>
- <td><code>-b, --bare</code></td>
- <td>
- Compile the JavaScript without the
- <a href="#lexical_scope">top-level function safety wrapper</a>.
- </td>
- </tr>
- <tr>
- <td><code>-t, --tokens</code></td>
- <td>
- Instead of parsing the CoffeeScript, just lex it, and print out the
- token stream: <tt>[IDENTIFIER square] [ASSIGN =] [PARAM_START (]</tt> ...
- </td>
- </tr>
- <tr>
- <td><code>-n, --nodes</code></td>
- <td>
- Instead of compiling the CoffeeScript, just lex and parse it, and print
- out the parse tree:
-<pre class="no_bar">
-Expressions
- Assign
- Value "square"
- Code "x"
- Op *
- Value "x"
- Value "x"</pre>
- </td>
- </tr>
- <tr>
- <td><code>--nodejs</code></td>
- <td>
- The <tt>node</tt> executable has some useful options you can set,
- such as<br /> <tt>--debug</tt>, <tt>--debug-brk</tt> and <tt>--max-stack-size</tt>. Use this
- flag to forward options directly to Node.js.
- </td>
- </tr>
- </table>
-
- <p>
- <b>Examples:</b>
- </p>
-
- <ul>
- <li>
- Compile a directory tree of <tt>.coffee</tt> files in <tt>src</tt> into a parallel
- tree of <tt>.js</tt> files in <tt>lib</tt>:<br />
- <tt>coffee --compile --output lib/ src/</tt>
- </li>
- <li>
- Watch a file for changes, and recompile it every time the file is saved:<br />
- <tt>coffee --watch --compile experimental.coffee</tt>
- </li>
- <li>
- Concatenate a list of files into a single script:<br />
- <tt>coffee --join project.js --compile src/*.coffee</tt>
- </li>
- <li>
- Print out the compiled JS from a one-liner:<br />
- <tt>coffee -bpe "alert i for i in [0..10]"</tt>
- </li>
- <li>
- All together now, watch and recompile an entire project as you work on it:<br />
- <tt>coffee -o lib/ -cw src/</tt>
- </li>
- <li>
- Start the CoffeeScript REPL (<tt>Ctrl-D</tt> to exit, <tt>Ctrl-V</tt>for multi-line):<br />
- <tt>coffee</tt>
- </li>
- </ul>
-
- <h2>
- <span id="language" class="bookmark"></span>
- Language Reference
- </h2>
-
- <p>
- <i>
- This reference is structured so that it can be read from top to bottom,
- if you like. Later sections use ideas and syntax previously introduced.
- Familiarity with JavaScript is assumed.
- In all of the following examples, the source CoffeeScript is provided on
- the left, and the direct compilation into JavaScript is on the right.
- </i>
- </p>
-
- <p>
- <i>
- Many of the examples can be run (where it makes sense) by pressing the <b>run</b>
- button on the right, and can be loaded into the "Try CoffeeScript"
- console by pressing the <b>load</b> button on the left.
- </i>
- <p>
- First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code.
- You don't need to use semicolons <tt>;</tt> 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
- <tt>{ }</tt> to surround blocks of code in <a href="#literals">functions</a>,
- <a href="#conditionals">if-statements</a>,
- <a href="#switch">switch</a>, and <a href="#try">try/catch</a>,
- use indentation.
- </p>
-
- <p>
- You don't need to use parentheses to invoke a function if you're passing
- arguments. The implicit call wraps forward to the end of the line or block expression.<br />
- <tt>console.log sys.inspect object</tt> &rarr; <tt>console.log(sys.inspect(object));</tt>
- </p>
-
- <p>
- <span id="literals" class="bookmark"></span>
- <b class="header">Functions</b>
- Functions are defined by an optional list of parameters in parentheses,
- an arrow, and the function body. The empty function looks like this:
- <tt>-></tt>
- </p>
- <div class='code'><pre class="idle"><span class="FunctionName">square </span><span class="Keyword">=</span> <span class="FunctionArgument">(x)</span> <span class="Storage">-&gt;</span> x <span class="Keyword">*</span> x
-<span class="FunctionName">cube </span><span class="Keyword">=</span> <span class="FunctionArgument">(x)</span> <span class="Storage">-&gt;</span> square(x) <span class="Keyword">*</span> x
-</pre><pre class="idle"><span class="Storage">var</span> cube, square;
-
-<span class="FunctionName">square</span> = <span class="Storage">function</span>(<span class="FunctionArgument">x</span>) {
- <span class="Keyword">return</span> x <span class="Keyword">*</span> x;
-};
-
-<span class="FunctionName">cube</span> = <span class="Storage">function</span>(<span class="FunctionArgument">x</span>) {
- <span class="Keyword">return</span> square(x) <span class="Keyword">*</span> x;
-};
-</pre><script>window.example2 = "square = (x) -> x * x\ncube = (x) -> square(x) * x\n\nalert cube(5)"</script><div class='minibutton load' onclick='javascript: loadConsole(example2);'>load</div><div class='minibutton ok' onclick='javascript: var cube, square;
-
-square = function(x) {
- return x * x;
-};
-
-cube = function(x) {
- return square(x) * x;
-};
-;alert(cube(5));'>run: cube(5)</div><br class='clear' /></div>
- <p>
- Functions may also have default values for arguments. Override the default
- value by passing a non-null argument.
- </p>
- <div class='code'><pre class="idle"><span class="FunctionName">fill </span><span class="Keyword">=</span> <span class="FunctionArgument">(container, liquid = &quot;coffee&quot;)</span> <span class="Storage">-&gt;</span>
- <span class="String"><span class="String">&quot;</span>Filling the <span class="String"><span class="String">#{</span>container<span class="String">}</span></span> with <span class="String"><span class="String">#{</span>liquid<span class="String">}</span></span>...<span class="String">&quot;</span></span>
-
-
-
-
-
-
-</pre><pre class="idle"><span class="Storage">var</span> fill;
-
-<span class="FunctionName">fill</span> = <span class="Storage">function</span>(<span class="FunctionArgument">container, liquid</span>) {
- <span class="Keyword">if</span> (liquid <span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) {
- liquid <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>coffee<span class="String">&quot;</span></span>;
- }
- <span class="Keyword">return</span> <span class="String"><span class="String">&quot;</span>Filling the <span class="String">&quot;</span></span> <span class="Keyword">+</span> container <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> with <span class="String">&quot;</span></span> <span class="Keyword">+</span> liquid <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span>...<span class="String">&quot;</span></span>;
-};
-</pre><script>window.example3 = "fill = (container, liquid = \"coffee\") ->\n \"Filling the #{container} with #{liquid}...\"\n\nalert fill(\"cup\")"</script><div class='minibutton load' onclick='javascript: loadConsole(example3);'>load</div><div class='minibutton ok' onclick='javascript: var fill;
-
-fill = function(container, liquid) {
- if (liquid == null) {
- liquid = "coffee";
- }
- return "Filling the " + container + " with " + liquid + "...";
-};
-;alert(fill("cup"));'>run: fill("cup")</div><br class='clear' /></div>
-
- <p>
- <span id="objects_and_arrays" class="bookmark"></span>
- <b class="header">Objects and Arrays</b>
- 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 <a href="http://yaml.org">YAML</a>.
- </p>
- <div class='code'><pre class="idle">song <span class="Keyword">=</span> [<span class="String"><span class="String">&quot;</span>do<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>re<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>mi<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>fa<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>so<span class="String">&quot;</span></span>]
-
-singers <span class="Keyword">=</span> {Jagger: <span class="String"><span class="String">&quot;</span>Rock<span class="String">&quot;</span></span>, Elvis: <span class="String"><span class="String">&quot;</span>Roll<span class="String">&quot;</span></span>}
-
-bitlist <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>
-]
-
-kids <span class="Keyword">=</span>
- brother:
- name: <span class="String"><span class="String">&quot;</span>Max<span class="String">&quot;</span></span>
- age: <span class="Number">11</span>
- sister:
- name: <span class="String"><span class="String">&quot;</span>Ida<span class="String">&quot;</span></span>
- age: <span class="Number">9</span>
-
-
-</pre><pre class="idle"><span class="Storage">var</span> bitlist, kids, singers, song;
-
-song <span class="Keyword">=</span> [<span class="String"><span class="String">&quot;</span>do<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>re<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>mi<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>fa<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>so<span class="String">&quot;</span></span>];
-
-singers <span class="Keyword">=</span> {
- Jagger: <span class="String"><span class="String">&quot;</span>Rock<span class="String">&quot;</span></span>,
- Elvis: <span class="String"><span class="String">&quot;</span>Roll<span class="String">&quot;</span></span>
-};
-
-bitlist <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>];
-
-kids <span class="Keyword">=</span> {
- brother: {
- name: <span class="String"><span class="String">&quot;</span>Max<span class="String">&quot;</span></span>,
- age: <span class="Number">11</span>
- },
- sister: {
- name: <span class="String"><span class="String">&quot;</span>Ida<span class="String">&quot;</span></span>,
- age: <span class="Number">9</span>
- }
-};
-</pre><script>window.example4 = "song = [\"do\", \"re\", \"mi\", \"fa\", \"so\"]\n\nsingers = {Jagger: \"Rock\", Elvis: \"Roll\"}\n\nbitlist = [\n 1, 0, 1\n 0, 0, 1\n 1, 1, 0\n]\n\nkids =\n brother:\n name: \"Max\"\n age: 11\n sister:\n name: \"Ida\"\n age: 9\n\nalert song.join(\" ... \")"</script><div class='minibutton load' onclick='javascript: loadConsole(example4);'>load</div><div class='minibutton ok' onclick='javascript: var bitlist, kids, singers, song;
-
-song = ["do", "re", "mi", "fa", "so"];
-
-singers = {
- Jagger: "Rock",
- Elvis: "Roll"
-};
-
-bitlist = [1, 0, 1, 0, 0, 1, 1, 1, 0];
-
-kids = {
- brother: {
- name: "Max",
- age: 11
- },
- sister: {
- name: "Ida",
- age: 9
- }
-};
-;alert(song.join(" ... "));'>run: song.join(" ... ")</div><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 reserved words
- used as keys in objects 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>).attr class: <span class="String"><span class="String">'</span>active<span class="String">'</span></span>
-
-log object.<span class="Storage">class</span>
-
-
-</pre><pre class="idle">
-<span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).attr({
- <span class="String"><span class="String">&quot;</span>class<span class="String">&quot;</span></span>: <span class="String"><span class="String">'</span>active<span class="String">'</span></span>
-});
-
-<span class="LibraryFunction">log</span>(object[<span class="String"><span class="String">&quot;</span>class<span class="String">&quot;</span></span>]);
-</pre><script>window.example5 = "$('.account').attr class: 'active'\n\nlog object.class\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example5);'>load</div><br class='clear' /></div>
-
- <p>
- <span id="lexical_scope" class="bookmark"></span>
- <b class="header">Lexical Scoping and Variable Safety</b>
- The CoffeeScript compiler takes care to make sure that all of your variables
- are properly declared within lexical scope &mdash; you never need to write
- <tt>var</tt> yourself.
- </p>
- <div class='code'><pre class="idle">outer <span class="Keyword">=</span> <span class="Number">1</span>
-<span class="FunctionName">changeNumbers </span><span class="Keyword">=</span> <span class="Keyword">-</span><span class="Keyword">&gt;</span>
- inner <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">1</span>
- outer <span class="Keyword">=</span> <span class="Number">10</span>
-inner <span class="Keyword">=</span> changeNumbers()
-</pre><pre class="idle"><span class="Storage">var</span> changeNumbers, inner, outer;
-
-outer <span class="Keyword">=</span> <span class="Number">1</span>;
-
-<span class="FunctionName">changeNumbers</span> = <span class="Storage">function</span>() {
- <span class="Storage">var</span> inner;
- inner <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">1</span>;
- <span class="Keyword">return</span> outer <span class="Keyword">=</span> <span class="Number">10</span>;
-};
-
-inner <span class="Keyword">=</span> changeNumbers();
-</pre><script>window.example6 = "outer = 1\nchangeNumbers = ->\n inner = -1\n outer = 10\ninner = changeNumbers()\n\nalert inner"</script><div class='minibutton load' onclick='javascript: loadConsole(example6);'>load</div><div class='minibutton ok' onclick='javascript: var changeNumbers, inner, outer;
-
-outer = 1;
-
-changeNumbers = function() {
- var inner;
- inner = -1;
- return outer = 10;
-};
-
-inner = changeNumbers();
-;alert(inner);'>run: inner</div><br class='clear' /></div>
- <p>
- Notice how all of the variable declarations have been pushed up to
- the top of the closest scope, the first time they appear.
- <b>outer</b> is not redeclared within the inner function, because it's
- already in scope; <b>inner</b> within the function, on the other hand,
- should not be able to change the value of the external variable of the same name, and
- therefore has a declaration of its own.
- </p>
- <p>
- This behavior is effectively identical to Ruby's scope for local variables.
- Because you don't have direct access to the <tt>var</tt> keyword,
- it's impossible to shadow an outer variable on purpose, you may only refer
- to it. So be careful that you're not reusing the name of an external
- variable accidentally, if you're writing a deeply nested function.
- </p>
- <p>
- Although suppressed within this documentation for clarity, all
- CoffeeScript output is wrapped in an anonymous function:
- <tt>(function(){ ... })();</tt> This safety wrapper, combined with the
- automatic generation of the <tt>var</tt> keyword, make it exceedingly difficult
- to pollute the global namespace by accident.
- </p>
- <p>
- 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>
- 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
- CommonJS and the browser: <tt>exports ? this</tt>
- </p>
-
- <p>
- <span id="conditionals" class="bookmark"></span>
- <b class="header">If, Else, Unless, and Conditional Assignment</b>
- <b>If/else</b> statements can be written without the use of parentheses and
- curly brackets. As with functions and other block expressions,
- multi-line conditionals are delimited by indentation. There's also a handy
- postfix form, with the <tt>if</tt> or <tt>unless</tt> at the end.
- </p>
- <p>
- CoffeeScript can compile <b>if</b> statements into JavaScript expressions,
- using the ternary operator when possible, and closure wrapping otherwise. There
- is no explicit ternary statement in CoffeeScript &mdash; you simply use
- a regular <b>if</b> statement on a single line.
- </p>
- <div class='code'><pre class="idle">mood <span class="Keyword">=</span> greatlyImproved <span class="Keyword">if</span> singing
-
-<span class="Keyword">if</span> happy <span class="Keyword">and</span> knowsIt
- clapsHands()
- chaChaCha()
-<span class="Keyword">else</span>
- showIt()
-
-date <span class="Keyword">=</span> <span class="Keyword">if</span> friday <span class="Keyword">then</span> sue <span class="Keyword">else</span> jill
-
-
-
-</pre><pre class="idle"><span class="Storage">var</span> date, mood;
-
-&