module Js:sig
..end
This module provides types and functions to interoperate with
Javascript values, and gives access to Javascript standard
objects.
null
and undefined
values.type +'a
opt
type +'a
optdef
val null : 'a opt
null
value.val some : 'a -> 'a opt
val undefined : 'a optdef
undefined
valueval def : 'a -> 'a optdef
module type OPT =sig
..end
module Opt:OPT
with type 'a t = 'a opt
module Optdef:OPT
with type 'a t = 'a optdef
type +'a
t
type +'a
meth
<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 +'a
gen_prop
type'a
readonly_prop =< get : 'a > gen_prop
<p : t Js.readonly_prop> Js.t
has a read-only property p
of type t
.type'a
writeonly_prop =< set : 'a -> unit > gen_prop
<p : t Js.writeonly_prop> Js.t
has a write-only property p
of type t
.type'a
prop =< get : 'a; set : 'a -> unit > gen_prop
<p : t Js.writeonly_prop> Js.t
has a read/write property p
of type t
.type'a
optdef_prop =< get : 'a optdef; set : 'a -> unit > gen_prop
t
, but if you read
them, you will get a value of type t optdef
(that may be
undefined
).typefloat_prop =
< get : float t; set : float -> unit > gen_prop
float
, but you will get back a
native Javascript number of type float t
.type +'a
constr
(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 (-'a, +'b)
meth_callback
(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'a
callback =(unit, 'a) meth_callback
this
implicit parameter.val wrap_callback : ('a -> 'b) -> ('c, 'a -> 'b) meth_callback
val wrap_meth_callback : ('c -> 'a -> 'b) -> ('c, 'a -> 'b) meth_callback
this
implicit parameter.val _true : bool t
true
boolean.val _false : bool t
false
boolean.type
match_result_handle
Js.match_result
to get the corresponding MatchResult
object.
(This type is used to resolved the mutual dependency between
string and array type definitions.)type
string_array
Array
object using function Js.str_array
.
(This type is used to resolved the mutual dependency between
string and array type definitions.)class type js_string =object
..end
class type regExp =object
..end
class type string_constr =object
..end
val string : string -> js_string t
val regExp : (js_string t -> regExp t) constr
RegExp
objects. The expression jsnew regExp (s)
builds the regular expression specified by string s
.val regExp_withFlags : (js_string t -> js_string t -> regExp t) constr
RegExp
objects. The expression
jsnew regExp (s, f)
builds the regular expression specified by
string s
using flags f
.val regExp_copy : (regExp t -> regExp t) constr
RegExp
objects. The expression
jsnew regExp (r)
builds a copy of regular expression r
.class type['a]
js_array =object
..end
val array_empty : 'a js_array t constr
Array
objects. The expression
jsnew array_empty ()
returns an empty array.val array_length : (int -> 'a js_array t) constr
Array
objects. The expression
jsnew array_empty (l)
returns an array of length l
.val array_get : 'a #js_array t -> int -> 'a optdef
array_get a i
returns the element at index i
of array a
. Returns undefined
if there is no element at
this index.val array_set : 'a #js_array t -> int -> 'a -> unit
array_set a i v
puts v
at index i
in
array a
.class type match_result =object
..end
val str_array : string_array t -> js_string t js_array t
string_array t
object into an array of
string. (Used to resolved the mutual dependency between string
and array type definitions.)val match_result : match_result_handle t -> match_result t
MatchResult
object.
(Used to resolved the mutual dependency between string
and array type definitions.)class type number =object
..end
val number_of_float : float -> number t
val float_of_number : number t -> float
class type date =object
..end
val date_now : date t constr
Date
objects: new date_now ()
returns a
Date
object initialized with the current date.val date_fromTimeValue : (float -> date t) constr
Date
objects: new date_fromTimeValue (t)
returns a
Date
object initialized with the time value t
.val date_month : (int -> int -> date t) constr
Date
objects: new date_fromTimeValue (y, m)
returns a Date
object corresponding to year y
and month m
.val date_day : (int -> int -> int -> date t) constr
Date
objects: new date_fromTimeValue (y, m, d)
returns a Date
object corresponding to year y
, month m
and
day d
.val date_hour : (int -> int -> int -> int -> date t) constr
Date
objects: new date_fromTimeValue (y, m, d, h)
returns a Date
object corresponding to year y
to hour h
.val date_min : (int -> int -> int -> int -> int -> date t) constr
Date
objects: new date_fromTimeValue (y, m, d, h, m')
returns a Date
object corresponding to year y
to minute m'
.val date_sec : (int -> int -> int -> int -> int -> int -> date t) constr
Date
objects:
new date_fromTimeValue (y, m, d, h, m', s)
returns a Date
object corresponding to year y
to second s
.val date_ms : (int -> int -> int -> int -> int -> int -> int -> date t) constr
Date
objects:
new date_fromTimeValue (y, m, d, h, m', s, ms)
returns a Date
object corresponding to year y
to millisecond ms
.class type date_constr =object
..end
val date : date_constr t
class type math =object
..end
val math : math t
val decodeURI : js_string t -> js_string t
val decodeURIComponent : js_string t -> js_string t
val encodeURI : js_string t -> js_string t
val encodeURIComponent : js_string t -> js_string t
encodeURI
, but also encode URI reserved characters.val escape : js_string t -> js_string t
val unescape : js_string t -> js_string t
val isNaN : 'a -> bool
val parseInt : js_string t -> int
val parseFloat : js_string t -> float t
val bool : bool -> bool t
val to_bool : bool t -> bool
val string : string -> js_string t
val to_string : js_string t -> string
val float : float -> float t
val to_float : float t -> float
val array : 'a array -> 'a js_array t
val to_array : 'a js_array t -> 'a array
val bytestring : string -> js_string t
val to_bytestring : js_string t -> string
val coerce : 'a -> ('a -> 'b Opt.t) -> ('a -> 'b) -> 'b
coerce v c f
attempts to apply coercion c
to value v
.
If the coercion returns null
, function f
is called.val coerce_opt : 'a Opt.t -> ('a -> 'b Opt.t) -> ('a -> 'b) -> 'b
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)
val typeof : < .. > t -> js_string t
val instanceof : < .. > t -> 'a constr -> bool
module Unsafe:sig
..end