Module: Opal::Raw
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#call(func, *args, &block) ⇒ Object
(also: #method_missing)
Call the global javascript function with the given arguments.
-
#delete(object, property) ⇒ Object
Use delete to remove a property from an object.
-
#global ⇒ Object
The global object.
-
#in(property, object) ⇒ Object
Use in to check for a property in an object.
-
#instanceof(value, func) ⇒ Object
Use instanceof to return whether value is an instance of the function.
- #new(func, *args, &block) ⇒ Object
-
#typeof(value) ⇒ Object
Use typeof to return the underlying javascript type of value.
-
#void(expr) ⇒ Object
Use void to return undefined.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Method Details
#[](name) ⇒ Object
65 66 67 |
# File 'opal/stdlib/opal/raw.rb', line 65 def [](name) `Opal.global[#{name}]` end |
#call(func, *args, &block) ⇒ Object Also known as: method_missing
Call the global javascript function with the given arguments.
59 60 61 62 63 |
# File 'opal/stdlib/opal/raw.rb', line 59 def call(func, *args, &block) g = global args << block if block g.JS[func].JS.apply(g, args) end |
#delete(object, property) ⇒ Object
Use delete to remove a property from an object.
9 10 11 |
# File 'opal/stdlib/opal/raw.rb', line 9 def delete(object, property) `delete #{object}[#{property}]` end |
#global ⇒ Object
The global object
14 15 16 |
# File 'opal/stdlib/opal/raw.rb', line 14 def global `Opal.global` end |
#in(property, object) ⇒ Object
Use in to check for a property in an object.
19 20 21 |
# File 'opal/stdlib/opal/raw.rb', line 19 def in(property, object) `#{property} in #{object}` end |
#instanceof(value, func) ⇒ Object
Use instanceof to return whether value is an instance of the function.
24 25 26 |
# File 'opal/stdlib/opal/raw.rb', line 24 def instanceof(value, func) `#{value} instanceof #{func}` end |
#new(func, *args, &block) ⇒ Object
30 31 32 33 34 |
# File 'opal/stdlib/opal/raw.rb', line 30 def new(func, *args, &block) args.insert(0, `this`) args << block if block `new (#{func}.bind.apply(#{func}, #{args}))()` end |
#typeof(value) ⇒ Object
Use typeof to return the underlying javascript type of value. Note that for undefined values, this will not work exactly like the javascript typeof operator, as the argument is evaluated before the function call.
48 49 50 |
# File 'opal/stdlib/opal/raw.rb', line 48 def typeof(value) `typeof #{value}` end |
#void(expr) ⇒ Object
Use void to return undefined.
53 54 55 56 |
# File 'opal/stdlib/opal/raw.rb', line 53 def void(expr) # Could use `undefined` here, but this is closer to the intent of the method `void #{expr}` end |