From 8b3926fb0c5830ad4eabca035a313e2b925ca8b6 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Fri, 8 Jan 2010 09:35:02 -0500 Subject: [PATCH] making extends equivalent to the Google Closure version --- lib/coffee_script/nodes.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index 1370299b..3fc6d6e9 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -269,9 +269,12 @@ module CoffeeScript end def compile_node(o={}) + constructor = o[:scope].free_variable sub, sup = @sub_object.compile(o), @super_object.compile(o) - "#{idt}#{sub}.__superClass__ = #{sup}.prototype;\n#{idt}" + - "#{sub}.prototype = new #{sup}();\n#{idt}" + + "#{idt}#{constructor} = function(){};\n#{idt}" + + "#{constructor}.prototype = #{sup}.prototype;\n#{idt}" + + "#{sub}.__superClass__ = #{sup}.prototype;\n#{idt}" + + "#{sub}.prototype = new #{constructor}();\n#{idt}" + "#{sub}.prototype.constructor = #{sub};" end