Javascript binding
This module provides types and functions to interoperate with Javascript values, and gives access to Javascript standard objects.
null
and undefined
values.Type of possibly null values.
Type of possibly undefined values.
Type of Javascript objects. The type parameter is used to specify more precisely an object.
Type used to specify method types:
a Javascript object
<m : t1 -> t2 -> ... -> tn -> t Js.meth> Js.t
has a Javascript method m
expecting n arguments
of types t1
to tn
and returns a value of type t
.
Type used to specify the properties of Javascript objects. In practice you should rarely need this type directly, but should rather use the type abbreviations below instead.
Type of read-only properties:
a Javascript object
<p : t Js.readonly_prop> Js.t
has a read-only property p
of type t
.
Type of write-only properties:
a Javascript object
<p : t Js.writeonly_prop> Js.t
has a write-only property p
of type t
.
Type of read/write properties:
a Javascript object
<p : t Js.writeonly_prop> Js.t
has a read/write property p
of type t
.
A value of type (t1 -> ... -> tn -> t Js.t) Js.constr
is a
Javascript constructor expecting n arguments of types t1
to tn
and returning a Javascript object of type t Js.t
. Use
the syntax extension jsnew c (e1, ..., en)
to build an object
using constructor c
and arguments e1
to en
.
Type of callback functions. A function of type
(u, t1 -> ... -> tn -> t) meth_callback
can be called
from Javascript with this
bound to a value of type u
and up to n arguments of types t1
to tn
. The system
takes care of currification, so less than n arguments can
be provided. As a special case, a callback of type
(t, unit -> t) meth_callback
can be called from Javascript
with no argument. It will behave as if it was called with a
single argument of type unit
.
Type of callback functions intended to be called without a
meaningful this
implicit parameter.
Wrap an OCaml function so that it can be invoked from Javascript.
Wrap an OCaml function so that it can be invoked from
Javascript. The first parameter of the function will be bound
to the value of the this
implicit parameter.
A handle to a match result. Use function Js.match_result
to get the corresponding MatchResult
object.
(This type is used to resolved the mutual dependency between
string and array type definitions.)
Opaque type for string arrays. You can get the actual Array
object using function Js.str_array
.
(This type is used to resolved the mutual dependency between
string and array type definitions.)
Specification of Javascript string objects.
Specification of Javascript regular arrays.
use Js.array_get
and Js.array_set
to access and set array elements.
Specification of match result objects
Convert a match result handle into a MatchResult
object.
(Used to resolved the mutual dependency between string
and array type definitions.)
Specification of Javascript number objects.
Specification of Javascript date objects.
Specification of the date constructor, considered as an object.
Conversion of booleans from OCaml to Javascript.
Conversion of booleans from Javascript to OCaml.
Apply a possibly failing coercion function.
coerce_opt v c f
attempts to apply coercion c
to value v
.
If v
is null
or the coercion returns null
, function f
is
called.
Typical usage is the following:
Js.coerce_opt (Dom_html.document##getElementById(id))
Dom_html.CoerceTo.div (fun _ -> assert false)
Invokes any available debugging functionality. If no debugging functionality is available, it has no effect. In practice, it will insert a "debugger;" statement in the generated javascript.
Unsafe Javascript operations
Access a Javascript variable. variable "foo"
will
return the current value of variable foo
.
Top type. Used for putting values of different types in a same array.
Get the value of an object property. The expression get o s
returns the value of property s
of object o
.
Set an object property. The expression set o s v
set the property s
of object o
to value v
.
Delete an object property. The expression delete o s
deletes property s
of object o
.
Performs a Javascript function call. The expression
call f o a
calls the Javascript function f
with the
arguments given by the array o
, and binding this
to o
.
Performs a Javascript function call. The expression
fun_call f a
calls the Javascript function f
with the
arguments given by the array o
.
Performs a Javascript method call. The expression
meth_call o m a
calls the Javascript method m
of object o
with the arguments given by the array a
.
Create a Javascript object. The expression new_obj c a
creates a Javascript object with constructor c
using the
arguments given by the array a
.
Creates a Javascript literal object. The expression
obj a
creates a Javascript object whose fields are given by
the array a
Asserts that an expression is pure, and can therefore be optimized away by the compiler if unused.
Evaluate Javascript code
js_expr e
will parse the JavaScript expression e
if e
is available at compile time or will failback to a
runtime evaluation. See eval_string
pure_js_expr str
behaves like pure_expr (fun () -> js_expr str)
.
Conversion of OCaml floats to Javascript numbers.
Conversion of Javascript numbers to OCaml floats.