diff --git a/documentation/js/super.js b/documentation/js/super.js index ce26399e..dc6e099a 100644 --- a/documentation/js/super.js +++ b/documentation/js/super.js @@ -6,7 +6,9 @@ return alert(this.name + " moved " + meters + "m."); }; Snake = function Snake(name) { - return this.name = name; + var __a; + __a = this.name = name; + return Snake === this.constructor ? this : __a; }; Snake.__superClass__ = Animal.prototype; Snake.prototype = new Animal(); @@ -16,7 +18,9 @@ return Snake.__superClass__.move.call(this, 5); }; Horse = function Horse(name) { - return this.name = name; + var __a; + __a = this.name = name; + return Horse === this.constructor ? this : __a; }; Horse.__superClass__ = Animal.prototype; Horse.prototype = new Animal(); diff --git a/index.html b/index.html index dcbabd77..d1c3b168 100644 --- a/index.html +++ b/index.html @@ -1001,7 +1001,9 @@ Animal = function return alert(this.name + " moved " + meters + "m."); }; Snake = function Snake(name) { - return this.name = name; + var __a; + __a = this.name = name; + return Snake === this.constructor ? this : __a; }; Snake.__superClass__ = Animal.prototype; Snake.prototype = new Animal(); @@ -1011,7 +1013,9 @@ Snake.__superClass__ = Animal.return Snake.__superClass__.move.call(this, 5); }; Horse = function Horse(name) { - return this.name = name; + var __a; + __a = this.name = name; + return Horse === this.constructor ? this : __a; }; Horse.__superClass__ = Animal.prototype; Horse.prototype = new Animal(); @@ -1031,7 +1035,9 @@ Animal.prototype.move = function move(meters) { return alert(this.name + " moved " + meters + "m."); }; Snake = function Snake(name) { - return this.name = name; + var __a; + __a = this.name = name; + return Snake === this.constructor ? this : __a; }; Snake.__superClass__ = Animal.prototype; Snake.prototype = new Animal(); @@ -1041,7 +1047,9 @@ Snake.prototype.move = function move() { return Snake.__superClass__.move.call(this, 5); }; Horse = function Horse(name) { - return this.name = name; + var __a; + __a = this.name = name; + return Horse === this.constructor ? this : __a; }; Horse.__superClass__ = Animal.prototype; Horse.prototype = new Animal(); diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index 64463d29..7ce3fc5b 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -100,9 +100,12 @@ module CoffeeScript if node.statement? node.compile(o.merge(:return => true)) else - constructor = o[:top] && o[:last_assign] && o[:last_assign][0..0][/[A-Z]/] - prefix = constructor ? "if (#{o[:last_assign]} !== this.constructor) " : '' - "#{o[:indent]}#{prefix}return #{node.compile(o)};" + if o[:top] && o[:last_assign] && o[:last_assign][0..0][/[A-Z]/] + temp = o[:scope].free_variable + "#{o[:indent]}#{temp} = #{node.compile(o)};\n#{o[:indent]}return #{o[:last_assign]} === this.constructor ? this : #{temp};" + else + "#{o[:indent]}return #{node.compile(o)};" + end end else ending = node.statement? ? '' : ';'