Version: 0.1
Authors: Kevin Smith (ksmith@basho.com).
sasl
application is running.erlang_js
.js_driver:new/0
.js
module to execute Javascript.{ok, Port} = js_driver:new(). ok = js:define(Port, <<"function my_add(x, y) { return x + y; }">>). js:call(Port, <<"my_add">>, [100, 50]). {ok, 150}
InitFun = fun(Port) -> js:define(Port, <<"function my_square(x) { return x * x; }">>), ok end. {ok, Port} = js_driver:new(InitFun). js:call(Port, <<"my_square">>, [3]). {ok,9}
InitFun = fun(Port) -> js:define(Port, <<"var my_constant = 100; function constant_mult(x) { return x * my_constant; };">>), ok end. {ok, Port} = js_driver:new(InitFun). js:call(Port, <<"constant_mult">>, [5]). {ok, 500} js:call(Port, <<"constant_mult">>, [5], [{<<"my_constant">>, 200}]). {ok, 1000}
JS = <<"function my_add(x, y) { ejsLog(\"/tmp/foo.txt\", \"Hello, world!\"); return x + y; }">>. ok = js:define(Port, JS). %% Logging output is automatically timestamped and written to /tmp/foo.txt %% when the function runs {ok, 84} = js:call(Port, <<"my_add">>, [42, 42]).
Generated by EDoc, Mar 14 2025, 20:38:31.