Passing a class to the javascript context

8 views
Skip to first unread message

Emiliano Heyns

unread,
May 10, 2014, 8:00:42 AM5/10/14
to therub...@googlegroups.com
Is it possible to pass a class to the javascript context, such that if I have

ctx['Item'] = MyClass

I could then later do (in javascript)

var x = new Item(id);

and access methods etc?

Charles Lowell

unread,
May 12, 2014, 10:58:30 AM5/12/14
to Emiliano Heyns, therub...@googlegroups.com
Yep,

consider:

    class Foo
      def bar
        "baz"
      end
    end
    require 'v8'
    cxt = V8::Context.new
    cxt['Foo'] = Foo
    cxt.eval('new Foo().bar') #=> baz



cheers,
Charles

--
You received this message because you are subscribed to the Google Groups "The Ruby Racer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to therubyracer...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages