I try to build an application using js_of_ocaml. Let's say I have the following code in javascript :
function MyFunction(){ this.name = "a" }
MyFunction.prototype.setName = function(arg){ this.name = arg }
How to write in OCaml/js_of_caml a code that will have the same effect as the js code below ?
val myInstance = new MyFunction();
myInstance.setName("Joe");
I tried to write something like :
let onload _ =
let myInstance = Js.Unsafe.new_obj (Js.Unsafe.variable "MyFunction") [||] in
Js.Unsafe.call (Js.Unsafe.variable "MyFunction.prototype.setName") myIntance [|Js.Unsafe.inject "Joe"|];
Js._false ;;
let _ = Html.window##onload <- Html.handler onload;
The constructor is called but I have errors following so it doesn't seem to be the right way to do it. I have also tried the Js.Unsafe.meth_call function but it's not better.
Any help would be appreciated.