Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Jan 5, 2010
1 parent 20144ab commit 4f564de
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 9 deletions.
7 changes: 7 additions & 0 deletions documentation/coffee/overview.coffee
Expand Up @@ -18,5 +18,12 @@ math: {
cube: x => x * square(x)
}

# Splats:
race: winner, *runners =>
print(winner, runners)

# Existence:
alert("I knew it!") if elvis?

# Array comprehensions:
cubed_list: math.cube(num) for num in list
7 changes: 6 additions & 1 deletion documentation/index.html.erb
Expand Up @@ -108,7 +108,7 @@
For a longer CoffeeScript example, check out
<a href="documentation/underscore.html">Underscore.coffee</a>, a port
of <a href="http://documentcloud.github.com/underscore/">Underscore.js</a>
to CoffeeScript, which, when compiled, passes the complete Underscore test suite.
to CoffeeScript, which, when compiled, can pass the complete Underscore test suite.
</p>

<h2 id="installation">Installation and Usage</h2>
Expand Down Expand Up @@ -537,6 +537,11 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
</p>

<ul>
<li>
A clean, safe syntax for manipulating the prototype chain, and performing
inheritance. <a href="#inheritance"><b>extends</b> and <b>super</b></a> are the start of this, but
aren't a complete answer.
</li>
<li>
A CoffeeScript version of the compiler, perhaps using Alessandro Warth's
<a href="http://tinlizzie.org/ometa/">OMeta</a>.
Expand Down
2 changes: 1 addition & 1 deletion documentation/js/existence.js
@@ -1,6 +1,6 @@
(function(){
var solipsism;
if ((typeof mind !== 'undefined' && mind !== null) && !(typeof world !== 'undefined' && world !== null)) {
if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
solipsism = true;
}
})();
12 changes: 11 additions & 1 deletion documentation/js/overview.js
@@ -1,5 +1,5 @@
(function(){
var __a, __b, __c, __d, cubed_list, list, math, num, number, opposite_day, square;
var __a, __b, __c, __d, cubed_list, list, math, num, number, opposite_day, race, square;
// Assignment:
number = 42;
opposite_day = true;
Expand All @@ -21,6 +21,16 @@
return x * square(x);
}
};
// Splats:
race = function race(winner) {
var runners;
runners = Array.prototype.slice.call(arguments, 1);
return print(winner, runners);
};
// Existence:
if ((typeof elvis !== "undefined" && elvis !== null)) {
alert("I knew it!");
}
// Array comprehensions:
cubed_list = (function() {
__a = list;
Expand Down
6 changes: 5 additions & 1 deletion documentation/underscore.html
Expand Up @@ -9,6 +9,10 @@
body {
margin: 0; padding: 0;
}
pre.idle {
font-family: "Monaco", "Consolas", monospace;
font-size: 12px;
}
</style>

</head>
Expand Down Expand Up @@ -607,6 +611,6 @@
<span class="line-numbers"> 591 </span>
<span class="line-numbers"> 592 </span> <span class="Comment"><span class="Comment">#</span> Extracts the result from a wrapped and chained object.</span>
<span class="line-numbers"> 593 </span> <span class="FunctionName">wrapper.prototype.value</span><span class="Keyword">:</span> <span class="Storage">=&gt;</span> <span class="Variable">this</span>._wrapped
</pre>
</pre>
</body>
</html>
40 changes: 36 additions & 4 deletions index.html
Expand Up @@ -95,9 +95,16 @@ <h2 id="overview">Mini Overview</h2>
<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>
race<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>
cubed_list<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> __a, __b, __c, __d, cubed_list, list, math, num, number, opposite_day, square;
</pre><pre class="idle"><span class="Storage">var</span> __a, __b, __c, __d, cubed_list, list, math, num, number, opposite_day, race, square;
<span class="Comment"><span class="Comment">//</span> Assignment:</span>
number <span class="Keyword">=</span> <span class="Number">42</span>;
opposite_day <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
Expand All @@ -119,6 +126,16 @@ <h2 id="overview">Mini Overview</h2>
<span class="Keyword">return</span> x <span class="Keyword">*</span> square(x);
}
};
<span class="Comment"><span class="Comment">//</span> Splats:</span>
race <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">race</span>(<span class="FunctionArgument">winner</span>) {
<span class="Storage">var</span> runners;
runners <span class="Keyword">=</span> <span class="LibraryClassType">Array</span>.<span class="LibraryConstant">prototype</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="Comment"><span class="Comment">//</span> Existence:</span>
<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>);
}
<span class="Comment"><span class="Comment">//</span> Array comprehensions:</span>
cubed_list <span class="Keyword">=</span> (<span class="Storage">function</span>() {
__a <span class="Keyword">=</span> list;
Expand All @@ -132,7 +149,7 @@ <h2 id="overview">Mini Overview</h2>
}
<span class="Keyword">return</span> __c;
})();
</pre><button onclick='javascript: var __a, __b, __c, __d, cubed_list, list, math, num, number, opposite_day, square;
</pre><button onclick='javascript: var __a, __b, __c, __d, cubed_list, list, math, num, number, opposite_day, race, square;
// Assignment:
number = 42;
opposite_day = true;
Expand All @@ -154,6 +171,16 @@ <h2 id="overview">Mini Overview</h2>
return x * square(x);
}
};
// Splats:
race = function race(winner) {
var runners;
runners = Array.prototype.slice.call(arguments, 1);
return print(winner, runners);
};
// Existence:
if ((typeof elvis !== "undefined" && elvis !== null)) {
alert("I knew it!");
}
// Array comprehensions:
cubed_list = (function() {
__a = list;
Expand All @@ -173,7 +200,7 @@ <h2 id="overview">Mini Overview</h2>
For a longer CoffeeScript example, check out
<a href="documentation/underscore.html">Underscore.coffee</a>, a port
of <a href="http://documentcloud.github.com/underscore/">Underscore.js</a>
to CoffeeScript, which, when compiled, passes the complete Underscore test suite.
to CoffeeScript, which, when compiled, can pass the complete Underscore test suite.
</p>

<h2 id="installation">Installation and Usage</h2>
Expand Down Expand Up @@ -489,7 +516,7 @@ <h2>Language Reference</h2>
</p>
<div class='code'><pre class="idle">solipsism<span class="Keyword">:</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> mind<span class="Keyword">?</span> <span class="Keyword">and</span> <span class="Keyword">not</span> world<span class="Keyword">?</span>
</pre><pre class="idle"><span class="Storage">var</span> solipsism;
<span class="Keyword">if</span> ((<span class="Keyword">typeof</span> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">'</span>undefined<span class="String">'</span></span> <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> <span class="Keyword">!</span>(<span class="Keyword">typeof</span> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">'</span>undefined<span class="String">'</span></span> <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>)) {
<span class="Keyword">if</span> ((<span class="Keyword">typeof</span> mind <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> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> <span class="Keyword">!</span>(<span class="Keyword">typeof</span> world <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> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>)) {
solipsism <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
}
</pre><br class='clear' /></div>
Expand Down Expand Up @@ -1151,6 +1178,11 @@ <h2 id="contributing">Contributing</h2>
</p>

<ul>
<li>
A clean, safe syntax for manipulating the prototype chain, and performing
inheritance. <a href="#inheritance"><b>extends</b> and <b>super</b></a> are the start of this, but
aren't a complete answer.
</li>
<li>
A CoffeeScript version of the compiler, perhaps using Alessandro Warth's
<a href="http://tinlizzie.org/ometa/">OMeta</a>.
Expand Down
2 changes: 1 addition & 1 deletion lib/coffee_script/nodes.rb
Expand Up @@ -698,7 +698,7 @@ def initialize(expression)

def compile_node(o)
val = @expression.compile(o)
write("(typeof #{val} !== 'undefined' && #{val} !== null)")
write("(typeof #{val} !== \"undefined\" && #{val} !== null)")
end
end

Expand Down

0 comments on commit 4f564de

Please sign in to comment.