Permalink
Browse files

more docs

  • Loading branch information...
1 parent 20144ab commit 4f564dec60cdc5baf3422acaf6bf2c79f0bc3c8f @jashkenas jashkenas committed Jan 5, 2010
View
7 documentation/coffee/overview.coffee
@@ -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
View
7 documentation/index.html.erb
@@ -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>
@@ -538,6 +538,11 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<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>.
</li>
View
2 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;
}
})();
View
12 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;
@@ -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;
View
6 documentation/underscore.html
@@ -9,6 +9,10 @@
body {
margin: 0; padding: 0;
}
+ pre.idle {
+ font-family: "Monaco", "Consolas", monospace;
+ font-size: 12px;
+ }
</style>
</head>
@@ -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>
View
40 index.html
@@ -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>;
@@ -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;
@@ -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;
@@ -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;
@@ -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>
@@ -489,7 +516,7 @@ <h2 id="installation">Installation and Usage</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>
@@ -1152,6 +1179,11 @@ <h2 id="contributing">Contributing</h2>
<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>.
</li>
View
2 lib/coffee_script/nodes.rb
@@ -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

0 comments on commit 4f564de

Please sign in to comment.