How to bind a JS library for OCaml

Accessing a JS variable, ex: document:

Write in .ml:

let v = (Js.Unsafe.js_expr "window")##.document

Alternatively, the global object can be used. In the browser, it refers to window.

let v =

and in .mli:

val v : ... Js.t

Be careful the function Js.​Unsafe.​js_expr and the value Js.​Unsafe.​global are not typed. Verify the library documentation before writing the type.

Binding a JS function