Class: StyleScript::ExtendsNode
Overview
Node to extend an object’s prototype with an ancestor object. After goog.inherits from the Closure Library.
Constant Summary
Constants inherited from Node
Instance Method Summary collapse
-
#compile_node(o = {}) ⇒ Object
Hooking one constructor into another’s prototype chain.
-
#initialize(sub_object, super_object) ⇒ ExtendsNode
constructor
A new instance of ExtendsNode.
Methods inherited from Node
#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write
Constructor Details
#initialize(sub_object, super_object) ⇒ ExtendsNode
384 385 386 |
# File 'lib/style_script/nodes.rb', line 384 def initialize(sub_object, super_object) @sub_object, @super_object = sub_object, super_object end |
Instance Method Details
#compile_node(o = {}) ⇒ Object
Hooking one constructor into another’s prototype chain.
389 390 391 392 393 394 395 396 397 |
# File 'lib/style_script/nodes.rb', line 389 def compile_node(o={}) constructor = o[:scope].free_variable sub, sup = @sub_object.compile(o), @super_object.compile(o) "#{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 |