You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<spanclass="hljs-keyword">if</span> major <spanclass="hljs-keyword">is</span><spanclass="hljs-number">0</span><spanclass="hljs-keyword">and</span> minor < <spanclass="hljs-number">8</span>
591
591
<spanclass="hljs-built_in">console</span>.warn <spanclass="hljs-string">"Node 0.8.0+ required for CoffeeScript REPL"</span>
Copy file name to clipboardExpand all lines: docs/v1/index.html
+23-9
Original file line number
Diff line number
Diff line change
@@ -612,8 +612,8 @@
612
612
<p><strong>CoffeeScript is a little language that compiles into JavaScript.</strong> Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.</p>
613
613
<p>The golden rule of CoffeeScript is: <em>“It’s just JavaScript”</em>. 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, pretty-printed, and tends to run as fast or faster than the equivalent handwritten JavaScript.</p>
614
614
<p>The CoffeeScript compiler goes to great lengths to generate output JavaScript that runs in every JavaScript runtime, but there are exceptions. Use <ahref="#generator-functions">generator functions</a>, <ahref="#generator-iteration"><code>for…from</code></a>, or <ahref="#tagged-template-literals">tagged template literals</a> only if you know that your <ahref="http://kangax.github.io/compat-table/es6/">target runtimes can support them</a>. If you use <ahref="#modules">modules</a>, you will need to <ahref="#modules-note">use an additional tool to resolve them</a>.</p>
</blockquote><p><strong>CoffeeScript 2 is coming!</strong> It adds support for <ahref="/v2/#classes">ES2015 classes</a>, <ahref="/v2/#fat-arrow"><code>async</code>/<code>await</code></a>, and generates JavaScript using ES2015+ syntax. <ahref="/v2/">Learn more</a>.</p></p>
619
619
@@ -740,12 +740,14 @@ <h2>Overview</h2>
740
740
<h2>Installation</h2>
741
741
<p>The command-line version of <code>coffee</code> is available as a <ahref="https://nodejs.org/">Node.js</a> utility. The <ahref="/v1/browser-compiler/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 <ahref="#try">Try CoffeeScript</a>).</p>
742
742
<p>To install, first make sure you have a working copy of the latest stable version of <ahref="https://nodejs.org/">Node.js</a>. You can then install CoffeeScript globally with <ahref="https://www.npmjs.com/">npm</a>:</p>
</blockquote><p>The <code>coffee</code> and <code>cake</code> commands will first look in the current folder to see if CoffeeScript is installed locally, and use that version if so. This allows different versions of CoffeeScript to be installed globally and locally.</p>
750
+
749
751
<spanclass="bookmark" id="usage"></span>
750
752
<h2>Usage</h2>
751
753
<p>Once installed, you should have access to the <code>coffee</code> command, which can execute scripts, compile <code>.coffee</code> files into <code>.js</code>, and provide an interactive REPL. The <code>coffee</code> command takes the following options:</p>
</code></pre><script>window.example1="import 'local-file.coffee'\nimport 'coffee-script'\n\nimport _ from 'underscore'\nimport * as underscore from 'underscore'\n\nimport { now } from 'underscore'\nimport { now as currentTimestamp } from 'underscore'\nimport { first, last } from 'underscore'\nimport utilityBelt, { each } from 'underscore'\n\nexport default Math\nexport square = (x) -> x * x\nexport class Mathematics\n least: (x, y) -> if x < y then x else y\n\nexport { sqrt }\nexport { sqrt as squareRoot }\nexport { Mathematics as default, sqrt as squareRoot }\n\nexport * from 'underscore'\nexport { max, min } from 'underscore'\n"</script><divclass='minibutton load' onclick='javascript: loadConsole(example1);'>load</div><brclass='clear' /></div><divid="modules-note" class="bookmark"></div>
2411
+
</code></pre><script>window.example1="import 'local-file.coffee'\nimport 'coffeescript'\n\nimport _ from 'underscore'\nimport * as underscore from 'underscore'\n\nimport { now } from 'underscore'\nimport { now as currentTimestamp } from 'underscore'\nimport { first, last } from 'underscore'\nimport utilityBelt, { each } from 'underscore'\n\nexport default Math\nexport square = (x) -> x * x\nexport class Mathematics\n least: (x, y) -> if x < y then x else y\n\nexport { sqrt }\nexport { sqrt as squareRoot }\nexport { Mathematics as default, sqrt as squareRoot }\n\nexport * from 'underscore'\nexport { max, min } from 'underscore'\n"</script><divclass='minibutton load' onclick='javascript: loadConsole(example1);'>load</div><brclass='clear' /></div><divid="modules-note" class="bookmark"></div>
2410
2412
<p>Note that the CoffeeScript compiler <strong>does not resolve modules</strong>; writing an <code>import</code> or <code>export</code> statement in CoffeeScript will produce an <code>import</code> or <code>export</code> statement in the resulting output. It is your responsibility attach another transpiler, such as <ahref="https://github.com/google/traceur-compiler">Traceur Compiler</a>, <ahref="http://babeljs.io/">Babel</a> or <ahref="https://github.com/rollup/rollup">Rollup</a>, to convert this ES2015 syntax into code that will work in your target runtimes.</p>
2411
2413
<p>Also note that any file with an <code>import</code> or <code>export</code> statement will be output without a <ahref="#lexical-scope">top-level function safety wrapper</a>; in other words, importing or exporting modules will automatically trigger <ahref="#usage">bare</a> mode for that file. This is because per the ES2015 spec, <code>import</code> or <code>export</code> statements must occur at the topmost scope.</p>
<li>The <code>return</code> and <code>export</code> keywords can now accept implicit objects (defined by indentation, without needing braces).</li>
2543
+
<li>Support Unicode code point escapes (e.g. <code>\u{1F4A9}</code>).</li>
2544
+
<li>The <code>coffee</code> command now first looks to see if CoffeeScript is installed under <code>node_modules</code> in the current folder, and executes the <code>coffee</code> binary there if so; or otherwise it runs the globally installed one. This allows you to have one version of CoffeeScript installed globally and a different one installed locally for a particular project. (Likewise for the <code>cake</code> command.)</li>
2545
+
<li>Bugfixes for chained function calls not closing implicit objects or ternaries.</li>
2546
+
<li>Bugfixes for incorrect code generated by the <code>?</code> operator within a termary <code>if</code> statement.</li>
2547
+
<li>Fixed some tests, and failing tests now result in a nonzero exit code.</li>
0 commit comments