1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

removed all traces of 'extends' -- it's not any shorter or more convenient than just setting the prototype

This commit is contained in:
Jeremy Ashkenas 2009-12-22 12:08:29 -05:00
parent ec58d6fda2
commit e916d4648d
13 changed files with 27 additions and 38 deletions

View file

@ -3,13 +3,13 @@ Animal.prototype.move: meters =>
alert(this.name + " moved " + meters + "m.").
Snake: name => this.name: name.
Snake extends new Animal()
Snake.prototype: new Animal()
Snake.prototype.move: =>
alert("Slithering...")
super(5).
Horse: name => this.name: name.
Horse extends new Animal()
Horse.prototype: new Animal()
Horse.prototype.move: =>
alert("Galloping...")
super(45).

View file

@ -1,4 +1,6 @@
(function(){
// Eat lunch.
var lunch;
var a = ['toast', 'cheese', 'wine'];
var d = [];
@ -7,6 +9,7 @@
d[b] = food.eat();
}
lunch = d;
// Zebra-stripe a table.
var e = table;
for (var f=0, g=e.length; f<g; f++) {
var row = e[f];

View file

@ -1,3 +0,0 @@
(function(){
})();

View file

@ -1,4 +1,6 @@
(function(){
// CoffeeScript on the left, JS on the right.
var square = function(x) {
return x * x;
};

View file

@ -1,4 +1,8 @@
(function(){
// Comments start with hash marks. Periods mark the end of a block.
var left_hand = raining ? umbrella : parasol;
// To signal the beginning of the next expression,
// use "then", or a newline.
left_hand = raining ? umbrella : parasol;
})();

View file

@ -1,6 +1,5 @@
(function(){
var Animal = function() {
};
Animal.prototype.move = function(meters) {
return alert(this.name + " moved " + meters + "m.");

View file

@ -4,7 +4,9 @@
} else if (day === "Wednesday") {
go_to_the_park();
} else if (day === "Saturday") {
day === bingo_day ? go_to_bingo() : null;
if (day === bingo_day) {
go_to_bingo();
};
} else if (day === "Sunday") {
go_to_church();
} else {

View file

@ -145,13 +145,13 @@ Animal.prototype.move: meters =>
alert(this.name + " moved " + meters + "m.").
Snake: name => this.name: name.
Snake extends Animal
Snake.prototype: Animal
Snake.prototype.move: =>
alert('Slithering...')
super(5).
Horse: name => this.name: name.
Horse extends Animal
Horse.prototype: Animal
Horse.prototype.move: =>
alert('Galloping...')
super(45).

View file

@ -275,7 +275,9 @@ lunch<span class="Keyword">:</span> food.eat() <span class="Keyword">for</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">if</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> lunch;
</pre><pre class="idle">
<span class="Comment"><span class="Comment">//</span> Eat lunch.</span>
<span class="Storage">var</span> lunch;
<span class="Storage">var</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="Storage">var</span> d <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (<span class="Storage">var</span> b<span class="Keyword">=</span><span class="Number">0</span>, c<span class="Keyword">=</span>a.<span class="LibraryConstant">length</span>; b<span class="Keyword">&lt;</span>c; b<span class="Keyword">++</span>) {
@ -283,6 +285,7 @@ highlight(row) <span class="Keyword">for</span> row, i <span class="Keyword">in<
d[b] <span class="Keyword">=</span> food.eat();
}
lunch <span class="Keyword">=</span> d;
<span class="Comment"><span class="Comment">//</span> Zebra-stripe a table.</span>
<span class="Storage">var</span> e <span class="Keyword">=</span> table;
<span class="Keyword">for</span> (<span class="Storage">var</span> f<span class="Keyword">=</span><span class="Number">0</span>, g<span class="Keyword">=</span>e.<span class="LibraryConstant">length</span>; f<span class="Keyword">&lt;</span>g; f<span class="Keyword">++</span>) {
<span class="Storage">var</span> row <span class="Keyword">=</span> e[f];
@ -333,7 +336,6 @@ tom<span class="Keyword">:</span> <span class="Keyword">new</span> <span class="
sam.move()
tom.move()
</pre><pre class="idle"><span class="Storage">var</span> <span class="FunctionName">Animal</span> = <span class="Storage">function</span>() {
};
<span class="LibraryClassType">Animal</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>(<span class="FunctionArgument">meters</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">&quot;</span> moved <span class="String">&quot;</span></span> <span class="Keyword">+</span> meters <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span>m.<span class="String">&quot;</span></span>);
@ -359,7 +361,6 @@ tom.move()
sam.move();
tom.move();
</pre><button onclick='javascript: var Animal = function() {
};
Animal.prototype.move = function(meters) {
return alert(this.name + " moved " + meters + "m.");
@ -429,7 +430,9 @@ if (10 > 9) {
} <span class="Keyword">else</span> <span class="Keyword">if</span> (day <span class="Keyword">===</span> <span class="String"><span class="String">&quot;</span>Wednesday<span class="String">&quot;</span></span>) {
go_to_the_park();
} <span class="Keyword">else</span> <span class="Keyword">if</span> (day <span class="Keyword">===</span> <span class="String"><span class="String">&quot;</span>Saturday<span class="String">&quot;</span></span>) {
day <span class="Keyword">===</span> bingo_day ? go_to_bingo() : <span class="BuiltInConstant">null</span>;
<span class="Keyword">if</span> (day <span class="Keyword">===</span> bingo_day) {
go_to_bingo();
};
} <span class="Keyword">else</span> <span class="Keyword">if</span> (day <span class="Keyword">===</span> <span class="String"><span class="String">&quot;</span>Sunday<span class="String">&quot;</span></span>) {
go_to_church();
} <span class="Keyword">else</span> {

View file

@ -229,7 +229,7 @@
</dict>
<dict>
<key>match</key>
<string>\b(super|this|extends)\b</string>
<string>\b(super|this)\b</string>
<key>name</key>
<string>variable.language.cs</string>
</dict>

View file

@ -10,7 +10,7 @@ token TRY CATCH FINALLY THROW
token BREAK CONTINUE
token FOR IN WHILE
token SWITCH CASE
token EXTENDS SUPER
token SUPER
token DELETE
token NEWLINE
token COMMENT
@ -30,7 +30,7 @@ prechigh
right DELETE
left "."
right THROW FOR IN WHILE NEW
left UNLESS IF ELSE EXTENDS
left UNLESS IF ELSE
left ":"
right RETURN
preclow
@ -69,7 +69,6 @@ rule
| Call
| Code
| Operation
| Extend
;
# We have to take extra care to convert these statements into expressions.
@ -255,11 +254,6 @@ rule
SUPER "(" ArgList ")" { result = CallNode.new(:super, val[2]) }
;
# Extending a class.
Extend:
IDENTIFIER EXTENDS Expression { result = ExtendNode.new(val[0], val[2]) }
;
# The array literal.
Array:
"[" ArgList "]" { result = ArrayNode.new(val[1]) }

View file

@ -14,7 +14,7 @@ module CoffeeScript
"break", "continue",
"for", "in", "while",
"switch", "case",
"extends", "super",
"super",
"delete"]
# Token matching regexes.

View file

@ -213,21 +213,6 @@ module CoffeeScript
end
end
class ExtendNode < Node
attr_reader :subclass, :superclass
def initialize(subclass, superclass)
@subclass, @superclass = subclass, superclass
end
def compile(o={})
o = super(o)
"#{@subclass}.prototype = #{@superclass.compile(o)}"
end
end
# A value, indexed or dotted into, or vanilla.
class ValueNode < Node
attr_reader :literal, :properties, :last