class Java::OrgMozillaJavascript::BaseFunction
The base class for all JavaScript function objects.
Public Class Methods
inherited(klass)
click to toggle source
Calls superclass method
# File lib/rhino/rhino_ext.rb, line 222 def self.inherited(klass) # NOTE: in JRuby < 9.3 inherited won't be called for a Java class # ... so this happens pretty much only for `Rhino::Ruby::Function` klass.send(:include, Rhino::Ruby::FunctionCall) super(klass) end
Public Instance Methods
apply(this, *args)
click to toggle source
apply a function with the given context and (optional) arguments e.g. `fn.apply(obj, 1, 2)`
NOTE: That call from Ruby does not have the same semantics as JavaScript's Function#call but rather as Ruby's Method#call !
# File lib/rhino/rhino_ext.rb, line 254 def apply(this, *args) with_context do |context| begin args = Rhino.args_to_javascript(args, scope = current_scope(context)) __call__(context, scope, Rhino.to_javascript(this), args) rescue Rhino::JS::JavaScriptException => e raise Rhino::JSError.new(e) end end end
Also aliased as: methodcall
bind(this, *args)
click to toggle source
bind a JavaScript function into the given (this) context
# File lib/rhino/rhino_ext.rb, line 230 def bind(this, *args) with_context do |context| args = Rhino.args_to_javascript(args, scope = current_scope(context)) Rhino::JS::BoundFunction.new(context, scope, self, Rhino.to_javascript(this), args) end end
new(*args)
click to toggle source
use JavaScript functions constructors from Ruby as `fn.new`
# File lib/rhino/rhino_ext.rb, line 238 def new(*args) with_context do |context| begin scope = current_scope(context) construct(context, scope, Rhino.args_to_javascript(args, scope)) rescue Rhino::JS::JavaScriptException => e raise Rhino::JSError.new(e) end end end