got extends back in the language -- use it together with super

This commit is contained in:
Jeremy Ashkenas
2009-12-24 16:49:23 -08:00
parent 47812d9ea6
commit 1c83e68292
10 changed files with 62 additions and 38 deletions

View File

@@ -215,6 +215,20 @@ module CoffeeScript
end
end
# Node to extend an object's prototype with an ancestor object.
class ExtendsNode < Node
attr_reader :sub_object, :super_object
def initialize(sub_object, super_object)
@sub_object, @super_object = sub_object, super_object
end
def compile(o={})
"#{@sub_object.compile(o)}.prototype.__proto__ = #{@super_object.compile(o)}"
end
end
# A value, indexed or dotted into, or vanilla.
class ValueNode < Node
attr_reader :literal, :properties, :last