Module js

Convenience module for interacting with Javascript from Erlang.

Copyright © 2009-2010 Basho Technologies Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Authors: Kevin Smith (ksmith@basho.com).

Description

Convenience module for interacting with Javascript from Erlang. The functions provided by this module marshal bindings and function args into JSON before sending them to Javascript. While this does incur a certain amount of overhead it has the benefit of (mostly) preserving types as they roundtrip between Erlang and Javascript. Of course, this also means all Erlang values MUST BE convertable into JSON. In practice, this is less restricting than it sounds.

Function Index

call/3Call a function by name with a list of arguments.
call/4Call a function by name with a list of arguments and environmental bindings.
define/2Define one or more Javascript expressions.
define/3Define one or more Javascript expressions using a set of bindings.
eval/2Evaluate one or more Javascript expressions and return the results.

Function Details

call/3

call(Ctx::port(), FunctionName::binary(), Args::[any()]) -> {ok, Result} | {error, any()}

Call a function by name with a list of arguments. This is roughly the same as apply in most other languages.

call/4

call(Ctx::port(), FunctionName::binary(), Args::[any()], Bindings::[any()]) -> {ok, Result} | {error, any()}

Call a function by name with a list of arguments and environmental bindings. Bindings behave just like define/3.

define/2

define(Ctx::port(), Js::binary()) -> ok | {error, any()}

Define one or more Javascript expressions.

define/3

define(Ctx::port(), Js::binary(), Bindings::[any()]) -> ok | {error, any()}

Define one or more Javascript expressions using a set of bindings. Bindings are useful when the expressions use closures.

eval/2

eval(Ctx::port(), Js::binary()) -> {ok, any()} | {error, any()}

Evaluate one or more Javascript expressions and return the results


Generated by EDoc, Mar 24 2025, 11:53:57.