Skip to content

Communicate with JavaScript

Melange interoperates very well with JavaScript, and provides a wide array of features to create bindings to JavaScript code. A binding is a piece of code that references a JavaScript object or value and makes it available for use in Melange code. A very basic example of a binding is:

ocaml
external confirm : string -> bool = "window.confirm"
reasonml
external confirm: string => bool = "window.confirm";

The above code binds JavaScript's window.confirm function to a Melange function named confirm. Note how the binding includes type annotations so that there's no ambiguity about the types of the arguments and return value.


In this section: