Standard functions for manipulating possibly undefined values.
Types for specifying method and properties of Javascript objects
type+'a t
Type of Javascript objects. The type parameter is used to specify more precisely an object.
type+'a meth
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+'a gen_prop
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'a writeonly_prop = < set : 'a-> unit >gen_prop
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'a prop = < get : 'a ; set : 'a-> unit >gen_prop
Type of read/write properties: a Javascript object <p : t Js.writeonly_prop> Js.t has a read/write property p of type t.
type'a optdef_prop = < get : 'aoptdef ; set : 'a-> unit >gen_prop
Type of read/write properties that may be undefined: you can set them to a value of some type t, but if you read them, you will get a value of type t optdef (that may be undefined).
Object constructors
type+'a constr
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 new%js c (e1, ..., en) to build an object using constructor c and arguments e1 to en.
Callbacks to OCaml
type(-'a, +'b) meth_callback
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.
val wrap_callback : ('a->'b)->('c, 'a->'b)meth_callback
Wrap an OCaml function so that it can be invoked from Javascript.
val wrap_meth_callback : ('b->'a)->('b, 'a)meth_callback
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.)
type string_array
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.)
Decode a URI: replace by the corresponding byte all escape sequences but the ones corresponding to a URI reserved character and convert the string from UTF-8 to UTF-16.
Apply a possibly failing coercion function. coerce v c f attempts to apply coercion c to value v. If the coercion returns null, function f is called.
val coerce_opt : 'aOpt.t->('a->'bOpt.t)->('a->'b)->'b
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:
Tests whether a Javascript object is an instance of a given class.
Debugging operations.
val debugger : unit -> unit
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.
Export functionality.
Export values to module.exports if it exists or to the global object otherwise.
deprecated [since 4.0] Use [Js_error.raise_] instead.
val exn_with_js_backtrace : exn ->force:bool -> exn
Attach a JavasScript error to an OCaml exception. if force = false and a JavasScript error is already attached, it will do nothing. This function is useful to store and retrieve information about JavaScript stack traces.
Attaching JavasScript errors will happen automatically when compiling with --enable with-js-error.
deprecated [since 4.0] Use [Js_error.raise_] instead.
Extract a JavaScript error attached to an OCaml exception, if any. This is useful to inspect an eventual stack strace, especially when sourcemap is enabled.
deprecated [since 4.0] Use [Js_error.of_exn] instead.
The Error exception wrap javascript exceptions when caught by OCaml code. In case the javascript exception is not an instance of javascript Error, it will be serialized and wrapped into a Failure exception.
deprecated [since 4.0] Use [Js_error.Exn] instead.