To increase approachability for the Riak database, Basho wanted to provide a means to build various bits of client functionality in javascript. To enable this, they built a library called erlang_js that makes interacting with a SpiderMonkey interpreter pretty trivial. Let's look at how you could use it.

mix new js_playground cd js_playground vim mix.exs
 defp deps do [ {:erlang_js, github: "basho/erlang_js"} ] end
mix deps.get

Now we're just going to open up the tests and play around with this library. Open up test/js_playground_test.exs:

 test "getting data out of the JavaScript interpreter" do # First, we start this app and its dependencies :application.ensure_all_started(:erlang_js) # Next, we make a new instance of SpiderMonkey {:ok, js} = # Next, we define a variable in it that is wrapping a function :ok = :js.define(js, "var addOne = function(n) { return n+1; };") # Finally, we call the function with an erlang data type, and we...