mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
minor doc updates -- let's try pulling in the underscore test suite
This commit is contained in:
parent
2c1033f5da
commit
3e24cef69f
7 changed files with 79 additions and 60 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
test.coffee
|
test.coffee
|
||||||
parser.output
|
parser.output
|
||||||
|
test/fixtures/underscore
|
||||||
*.gem
|
*.gem
|
|
@ -64,6 +64,11 @@
|
||||||
preserved intact.
|
preserved intact.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Latest Version:</b>
|
||||||
|
<a href="http://gemcutter.org/gems/coffee-script">0.2.0</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
<h2>Table of Contents</h2>
|
<h2>Table of Contents</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(function(){
|
(function(){
|
||||||
var __a, __b, __c, __d, __e, __f, __g, food, i, lunch, row;
|
var __a, __b, __c, __d, __e, __f, food, i, lunch, row;
|
||||||
// Eat lunch.
|
// Eat lunch.
|
||||||
|
lunch = (function() {
|
||||||
__a = ['toast', 'cheese', 'wine'];
|
__a = ['toast', 'cheese', 'wine'];
|
||||||
__c = [];
|
__c = [];
|
||||||
for (__b in __a) {
|
for (__b in __a) {
|
||||||
|
@ -10,15 +11,14 @@
|
||||||
__c.push(__d);
|
__c.push(__d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lunch = __c;
|
return __c;
|
||||||
|
})();
|
||||||
// Zebra-stripe a table.
|
// Zebra-stripe a table.
|
||||||
__e = table;
|
__e = table;
|
||||||
__f = [];
|
|
||||||
for (i in __e) {
|
for (i in __e) {
|
||||||
if (__e.hasOwnProperty(i)) {
|
if (__e.hasOwnProperty(i)) {
|
||||||
row = __e[i];
|
row = __e[i];
|
||||||
i % 2 === 0 ? highlight(row) : null;
|
i % 2 === 0 ? highlight(row) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
__f;
|
|
||||||
})();
|
})();
|
|
@ -22,6 +22,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Array comprehensions:
|
// Array comprehensions:
|
||||||
|
cubed_list = (function() {
|
||||||
__a = list;
|
__a = list;
|
||||||
__c = [];
|
__c = [];
|
||||||
for (__b in __a) {
|
for (__b in __a) {
|
||||||
|
@ -31,5 +32,6 @@
|
||||||
__c.push(__d);
|
__c.push(__d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cubed_list = __c;
|
return __c;
|
||||||
|
})();
|
||||||
})();
|
})();
|
|
@ -4,7 +4,7 @@
|
||||||
change_numbers = function change_numbers() {
|
change_numbers = function change_numbers() {
|
||||||
var new_num;
|
var new_num;
|
||||||
num = 2;
|
num = 2;
|
||||||
return (new_num = 3);
|
return new_num = 3;
|
||||||
};
|
};
|
||||||
new_num = change_numbers();
|
new_num = change_numbers();
|
||||||
})();
|
})();
|
|
@ -6,7 +6,7 @@
|
||||||
return alert(this.name + " moved " + meters + "m.");
|
return alert(this.name + " moved " + meters + "m.");
|
||||||
};
|
};
|
||||||
Snake = function Snake(name) {
|
Snake = function Snake(name) {
|
||||||
return (this.name = name);
|
return this.name = name;
|
||||||
};
|
};
|
||||||
Snake.__superClass__ = Animal.prototype;
|
Snake.__superClass__ = Animal.prototype;
|
||||||
Snake.prototype = new Animal();
|
Snake.prototype = new Animal();
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
return Snake.__superClass__.move.call(this, 5);
|
return Snake.__superClass__.move.call(this, 5);
|
||||||
};
|
};
|
||||||
Horse = function Horse(name) {
|
Horse = function Horse(name) {
|
||||||
return (this.name = name);
|
return this.name = name;
|
||||||
};
|
};
|
||||||
Horse.__superClass__ = Animal.prototype;
|
Horse.__superClass__ = Animal.prototype;
|
||||||
Horse.prototype = new Animal();
|
Horse.prototype = new Animal();
|
||||||
|
|
59
index.html
59
index.html
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -35,6 +37,11 @@
|
||||||
preserved intact.
|
preserved intact.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Latest Version:</b>
|
||||||
|
<a href="http://gemcutter.org/gems/coffee-script">0.2.0</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
<h2>Table of Contents</h2>
|
<h2>Table of Contents</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -110,16 +117,18 @@ math <span class="Keyword">=</span> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
<span class="Comment"><span class="Comment">//</span> Array comprehensions:</span>
|
<span class="Comment"><span class="Comment">//</span> Array comprehensions:</span>
|
||||||
__a <span class="Keyword">=</span> list;
|
cubed_list <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||||
__c <span class="Keyword">=</span> [];
|
__a <span class="Keyword">=</span> list;
|
||||||
<span class="Keyword">for</span> (__b <span class="Keyword">in</span> __a) {
|
__c <span class="Keyword">=</span> [];
|
||||||
|
<span class="Keyword">for</span> (__b <span class="Keyword">in</span> __a) {
|
||||||
<span class="Keyword">if</span> (__a.hasOwnProperty(__b)) {
|
<span class="Keyword">if</span> (__a.hasOwnProperty(__b)) {
|
||||||
num <span class="Keyword">=</span> __a[__b];
|
num <span class="Keyword">=</span> __a[__b];
|
||||||
__d <span class="Keyword">=</span> math.cube(num);
|
__d <span class="Keyword">=</span> math.cube(num);
|
||||||
__c.<span class="LibraryFunction">push</span>(__d);
|
__c.<span class="LibraryFunction">push</span>(__d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cubed_list <span class="Keyword">=</span> __c;
|
<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, square;
|
||||||
// Assignment:
|
// Assignment:
|
||||||
number = 42;
|
number = 42;
|
||||||
|
@ -143,16 +152,18 @@ math = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Array comprehensions:
|
// Array comprehensions:
|
||||||
__a = list;
|
cubed_list = (function() {
|
||||||
__c = [];
|
__a = list;
|
||||||
for (__b in __a) {
|
__c = [];
|
||||||
|
for (__b in __a) {
|
||||||
if (__a.hasOwnProperty(__b)) {
|
if (__a.hasOwnProperty(__b)) {
|
||||||
num = __a[__b];
|
num = __a[__b];
|
||||||
__d = math.cube(num);
|
__d = math.cube(num);
|
||||||
__c.push(__d);
|
__c.push(__d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cubed_list = __c;
|
return __c;
|
||||||
|
})();
|
||||||
;alert(cubed_list);'>run: cubed_list</button><br class='clear' /></div>
|
;alert(cubed_list);'>run: cubed_list</button><br class='clear' /></div>
|
||||||
|
|
||||||
<h2 id="installation">Installation and Usage</h2>
|
<h2 id="installation">Installation and Usage</h2>
|
||||||
|
@ -379,7 +390,7 @@ num <span class="Keyword">=</span> <span class="Number">1</span>;
|
||||||
change_numbers <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">change_numbers</span>() {
|
change_numbers <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">change_numbers</span>() {
|
||||||
<span class="Storage">var</span> new_num;
|
<span class="Storage">var</span> new_num;
|
||||||
num <span class="Keyword">=</span> <span class="Number">2</span>;
|
num <span class="Keyword">=</span> <span class="Number">2</span>;
|
||||||
<span class="Keyword">return</span> (new_num <span class="Keyword">=</span> <span class="Number">3</span>);
|
<span class="Keyword">return</span> new_num <span class="Keyword">=</span> <span class="Number">3</span>;
|
||||||
};
|
};
|
||||||
new_num <span class="Keyword">=</span> change_numbers();
|
new_num <span class="Keyword">=</span> change_numbers();
|
||||||
</pre><button onclick='javascript: var change_numbers, new_num, num;
|
</pre><button onclick='javascript: var change_numbers, new_num, num;
|
||||||
|
@ -387,7 +398,7 @@ num = 1;
|
||||||
change_numbers = function change_numbers() {
|
change_numbers = function change_numbers() {
|
||||||
var new_num;
|
var new_num;
|
||||||
num = 2;
|
num = 2;
|
||||||
return (new_num = 3);
|
return new_num = 3;
|
||||||
};
|
};
|
||||||
new_num = change_numbers();
|
new_num = change_numbers();
|
||||||
;alert(new_num);'>run: new_num</button><br class='clear' /></div>
|
;alert(new_num);'>run: new_num</button><br class='clear' /></div>
|
||||||
|
@ -585,28 +596,28 @@ lunch<span class="Keyword">:</span> <span class="Variable">this</span>.eat(food)
|
||||||
|
|
||||||
<span class="Comment"><span class="Comment">#</span> Zebra-stripe a table.</span>
|
<span class="Comment"><span class="Comment">#</span> Zebra-stripe a table.</span>
|
||||||
highlight(row) <span class="Keyword">for</span> row, i <span class="Keyword">in</span> table <span class="Keyword">when</span> i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">is</span> <span class="Number">0</span>
|
highlight(row) <span class="Keyword">for</span> row, i <span class="Keyword">in</span> table <span class="Keyword">when</span> i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">is</span> <span class="Number">0</span>
|
||||||
</pre><pre class="idle"><span class="Storage">var</span> __a, __b, __c, __d, __e, __f, __g, food, i, lunch, row;
|
</pre><pre class="idle"><span class="Storage">var</span> __a, __b, __c, __d, __e, __f, food, i, lunch, row;
|
||||||
<span class="Comment"><span class="Comment">//</span> Eat lunch.</span>
|
<span class="Comment"><span class="Comment">//</span> Eat lunch.</span>
|
||||||
__a <span class="Keyword">=</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>];
|
lunch <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||||
__c <span class="Keyword">=</span> [];
|
__a <span class="Keyword">=</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>];
|
||||||
<span class="Keyword">for</span> (__b <span class="Keyword">in</span> __a) {
|
__c <span class="Keyword">=</span> [];
|
||||||
|
<span class="Keyword">for</span> (__b <span class="Keyword">in</span> __a) {
|
||||||
<span class="Keyword">if</span> (__a.hasOwnProperty(__b)) {
|
<span class="Keyword">if</span> (__a.hasOwnProperty(__b)) {
|
||||||
food <span class="Keyword">=</span> __a[__b];
|
food <span class="Keyword">=</span> __a[__b];
|
||||||
__d <span class="Keyword">=</span> <span class="Variable">this</span>.eat(food);
|
__d <span class="Keyword">=</span> <span class="Variable">this</span>.eat(food);
|
||||||
__c.<span class="LibraryFunction">push</span>(__d);
|
__c.<span class="LibraryFunction">push</span>(__d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lunch <span class="Keyword">=</span> __c;
|
<span class="Keyword">return</span> __c;
|
||||||
|
})();
|
||||||
<span class="Comment"><span class="Comment">//</span> Zebra-stripe a table.</span>
|
<span class="Comment"><span class="Comment">//</span> Zebra-stripe a table.</span>
|
||||||
__e <span class="Keyword">=</span> table;
|
__e <span class="Keyword">=</span> table;
|
||||||
__f <span class="Keyword">=</span> [];
|
|
||||||
<span class="Keyword">for</span> (i <span class="Keyword">in</span> __e) {
|
<span class="Keyword">for</span> (i <span class="Keyword">in</span> __e) {
|
||||||
<span class="Keyword">if</span> (__e.hasOwnProperty(i)) {
|
<span class="Keyword">if</span> (__e.hasOwnProperty(i)) {
|
||||||
row <span class="Keyword">=</span> __e[i];
|
row <span class="Keyword">=</span> __e[i];
|
||||||
i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">===</span> <span class="Number">0</span> ? highlight(row) : <span class="BuiltInConstant">null</span>;
|
i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">===</span> <span class="Number">0</span> ? highlight(row) : <span class="BuiltInConstant">null</span>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
__f;
|
|
||||||
</pre><br class='clear' /></div>
|
</pre><br class='clear' /></div>
|
||||||
<p>
|
<p>
|
||||||
If you're not iterating over an actual array, you can use a range to
|
If you're not iterating over an actual array, you can use a range to
|
||||||
|
@ -688,7 +699,7 @@ Animal <span class="Keyword">=</span> <span class="Storage">function</span> <spa
|
||||||
<span class="Keyword">return</span> <span class="LibraryFunction">alert</span>(<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">+</span> <span class="String"><span class="String">"</span> moved <span class="String">"</span></span> <span class="Keyword">+</span> meters <span class="Keyword">+</span> <span class="String"><span class="String">"</span>m.<span class="String">"</span></span>);
|
<span class="Keyword">return</span> <span class="LibraryFunction">alert</span>(<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">+</span> <span class="String"><span class="String">"</span> moved <span class="String">"</span></span> <span class="Keyword">+</span> meters <span class="Keyword">+</span> <span class="String"><span class="String">"</span>m.<span class="String">"</span></span>);
|
||||||
};
|
};
|
||||||
Snake <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">Snake</span>(<span class="FunctionArgument">name</span>) {
|
Snake <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">Snake</span>(<span class="FunctionArgument">name</span>) {
|
||||||
<span class="Keyword">return</span> (<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name);
|
<span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name;
|
||||||
};
|
};
|
||||||
Snake.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryConstant">prototype</span>;
|
Snake.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryConstant">prototype</span>;
|
||||||
<span class="LibraryClassType">Snake</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">Animal</span>();
|
<span class="LibraryClassType">Snake</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">Animal</span>();
|
||||||
|
@ -698,7 +709,7 @@ Snake.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryC
|
||||||
<span class="Keyword">return</span> Snake.__superClass__.move.<span class="LibraryFunction">call</span>(<span class="Variable">this</span>, <span class="Number">5</span>);
|
<span class="Keyword">return</span> Snake.__superClass__.move.<span class="LibraryFunction">call</span>(<span class="Variable">this</span>, <span class="Number">5</span>);
|
||||||
};
|
};
|
||||||
Horse <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">Horse</span>(<span class="FunctionArgument">name</span>) {
|
Horse <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">Horse</span>(<span class="FunctionArgument">name</span>) {
|
||||||
<span class="Keyword">return</span> (<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name);
|
<span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name;
|
||||||
};
|
};
|
||||||
Horse.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryConstant">prototype</span>;
|
Horse.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryConstant">prototype</span>;
|
||||||
<span class="LibraryClassType">Horse</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">Animal</span>();
|
<span class="LibraryClassType">Horse</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">Animal</span>();
|
||||||
|
@ -718,7 +729,7 @@ Animal.prototype.move = function move(meters) {
|
||||||
return alert(this.name + " moved " + meters + "m.");
|
return alert(this.name + " moved " + meters + "m.");
|
||||||
};
|
};
|
||||||
Snake = function Snake(name) {
|
Snake = function Snake(name) {
|
||||||
return (this.name = name);
|
return this.name = name;
|
||||||
};
|
};
|
||||||
Snake.__superClass__ = Animal.prototype;
|
Snake.__superClass__ = Animal.prototype;
|
||||||
Snake.prototype = new Animal();
|
Snake.prototype = new Animal();
|
||||||
|
@ -728,7 +739,7 @@ Snake.prototype.move = function move() {
|
||||||
return Snake.__superClass__.move.call(this, 5);
|
return Snake.__superClass__.move.call(this, 5);
|
||||||
};
|
};
|
||||||
Horse = function Horse(name) {
|
Horse = function Horse(name) {
|
||||||
return (this.name = name);
|
return this.name = name;
|
||||||
};
|
};
|
||||||
Horse.__superClass__ = Animal.prototype;
|
Horse.__superClass__ = Animal.prototype;
|
||||||
Horse.prototype = new Animal();
|
Horse.prototype = new Animal();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue