Class: NScript::ExtendsNode

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

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

Returns a new instance of ExtendsNode.



256
257
258
# File 'lib/nscript/parser/nodes.rb', line 256

def initialize(sub_object, super_object)
  @sub_object, @super_object = sub_object, super_object
end

Instance Method Details

#compile_node(o = {}) ⇒ Object



260
261
262
263
264
265
266
267
268
# File 'lib/nscript/parser/nodes.rb', line 260

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