Accessing or modifying a JS property to an element

When a property is missing in the OCaml interface of an element (for example
it has been dynamically added by a library), you can access using unsafe
features:

(Js.Unsafe.coerceelt)##blah

If you want to add yourself a new property:

(Js.Unsafe.coerceelt)##blah<-v

Here, v may be a JS value or an OCaml value.

If you want to do that in type safe manner, just define new types for the
extended elements, or wrap the unsafe functions inside a getter and setter.

Binding a JS object

Write in .ml and in .mli:

classtypemy_js_type=object(* read only property, read value with t##prop1 *)methodprop1:intreadonly_prop(* write only property, write value with t##prop2 <- 3.14 *)methodprop2:floatwriteonly_prop(* both read and write *)methodprop3:intprop(* method or property starting with a capital letter can be prepend
with an underscore. *)method_Array:...(* to access the JavasScript property or method Array *)(* Define two methods with differant types, that translate to
the same JavaScript method. *)methodmy_fun_int:int->unitmethmethodmy_fun_string:js_stringt->unitmeth(* Both will actually call the my_fun JavaScript method. *)(* To call a javascript method starting with one underscore *)method__hiddenfun:..method__hiddenfun_:..method__hiddenfun_something:..(* This will call the _hiddenfun Javascript method *)(* To call the javascript method '_' *)method__:..end

Example binding some constants:

For example if the JS class is used to define three constants thelib.Theclass.VALUEA, thelib.Theclass.VALUEB, thelib.Theclass.VALUEC,

Since ocaml doesn't allows method name to start with capitalised letter, we can add an _