Module: JS
Overview
The JS module provides syntax sugar for calling native javascript operators (e.g. typeof, instanceof, new, delete) and global functions (e.g. parseFloat, parseInt).
Instance Method Summary collapse
- 
  
    
      #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
#call(func, *args, &block) ⇒ Object Also known as: method_missing
Call the global javascript function with the given arguments.
      56 57 58 59 60  | 
    
      # File 'opal/stdlib/js.rb', line 56 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.
      6 7 8  | 
    
      # File 'opal/stdlib/js.rb', line 6 def delete(object, property) `delete #{object}[#{property}]` end  | 
  
#global ⇒ Object
The global object
      11 12 13  | 
    
      # File 'opal/stdlib/js.rb', line 11 def global `Opal.global` end  | 
  
#in(property, object) ⇒ Object
Use in to check for a property in an object.
      16 17 18  | 
    
      # File 'opal/stdlib/js.rb', line 16 def in(property, object) `#{property} in #{object}` end  | 
  
#instanceof(value, func) ⇒ Object
Use instanceof to return whether value is an instance of the function.
      21 22 23  | 
    
      # File 'opal/stdlib/js.rb', line 21 def instanceof(value, func) `#{value} instanceof #{func}` end  | 
  
#new(func, *args, &block) ⇒ Object
      27 28 29 30 31  | 
    
      # File 'opal/stdlib/js.rb', line 27 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.
      45 46 47  | 
    
      # File 'opal/stdlib/js.rb', line 45 def typeof(value) `typeof #{value}` end  | 
  
#void(expr) ⇒ Object
Use void to return undefined.
      50 51 52 53  | 
    
      # File 'opal/stdlib/js.rb', line 50 def void(expr) # Could use `undefined` here, but this is closer to the intent of the method `void #{expr}` end  |