Class: StyleScript::ExtendsNode

Inherits:
Node
  • Object
show all
Defined in:
lib/style_script/nodes.rb

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

Node::TAB

Instance Method Summary collapse

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