Class: RBelly::JS::Object

Inherits:
Base
  • Object
show all
Defined in:
lib/rbelly/js/object.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#properties, #return

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #can_put?, #default_value, #delete, #has_property?, #returned?

Constructor Details

#initialize(*args) ⇒ Object

Returns a new instance of Object.



22
23
24
25
26
27
# File 'lib/rbelly/js/object.rb', line 22

def initialize(*args)
  super()
  self['prototype'] = JS::ObjectPrototype.new
  self['valueOf'] = lambda { args.first || self }
  self['valueOf'].function = lambda { args.first || self }
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/rbelly/js/object.rb', line 4

def value
  @value
end

Class Method Details

.create(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rbelly/js/object.rb', line 6

def create(*args)
  arg = args.first
  return self.new if arg.nil? || arg == :undefined
  case arg
  when true, false
    JS::Boolean.new(arg)
  when Numeric
    JS::Number.new(arg)
  when ::String
    JS::String.new(arg)
  else
    self.new(arg)
  end
end