Skip to content

Instantly share code, notes, and snippets.

@presci
Created July 5, 2012 23:26
Show Gist options
  • Save presci/3057097 to your computer and use it in GitHub Desktop.
Save presci/3057097 to your computer and use it in GitHub Desktop.
erlang_js examples
1> {ok, JS}=js_driver:new().
{ok,#Port<0.1611>}
2> js:define(JS, <<"var hello=function(){return 'hello world';}">>).
ok
3> js:call(JS, <<"hello">>, []).
{ok,<<"hello world">>}
4> js:define(JS, <<"var kelly=function(){ return {\"hello\":\"world\"};}">>).
ok
5> js:call(JS, <<"kelly">>, []).
{ok,{struct,[{<<"hello">>,<<"world">>}]}}
6> js:define(JS, <<"var discovery=function(){return [{\"hello1\":\"world\"},{\"hello2\":\"world2\"}];}">>).
ok
7> js:call(JS, <<"discovery">>, []).
{ok,[{struct,[{<<"hello1">>,<<"world">>}]},
{struct,[{<<"hello2">>,<<"world2">>}]}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment