stopped using __proto__, instead, using a variant of goog.inherits for extends and super()

This commit is contained in:
Jeremy Ashkenas
2009-12-25 13:57:47 -08:00
parent f55b4cd8b6
commit e494d520ea
7 changed files with 41 additions and 24 deletions

View File

@@ -211,11 +211,12 @@ module CoffeeScript
def compile_super(args, o)
methname = o[:last_assign].sub(LEADING_DOT, '')
arg_part = args.empty? ? '' : ", #{args}"
"#{o[:proto_assign]}.prototype.__proto__.#{methname}.call(this#{arg_part})"
"#{o[:proto_assign]}.__superClass__.#{methname}.call(this#{arg_part})"
end
end
# Node to extend an object's prototype with an ancestor object.
# After goog.inherits from the Closure Library.
class ExtendsNode < Node
attr_reader :sub_object, :super_object
@@ -224,7 +225,10 @@ module CoffeeScript
end
def compile(o={})
"#{@sub_object.compile(o)}.prototype.__proto__ = #{@super_object.compile(o)}"
sub, sup = @sub_object.compile(o), @super_object.compile(o)
"#{sub}.__superClass__ = #{sup}.prototype;\n#{o[:indent]}" +
"#{sub}.prototype = new #{sup}();\n#{o[:indent]}" +
"#{sub}.prototype.constructor = #{sub}"
end
end