Search code examples
ocamljs-of-ocaml

How to call a js_of_ocaml method?


I have a one-line js_of_ocaml program:

Dom_html.window##scroll 100 100 ;

Which fails with the error:

File "tests/test_scrolling.ml", line 2, characters 0-23:
Error: This expression has type int -> int -> unit Js.meth
       but an expression was expected of type < get : 'a; .. > Js.gen_prop
Command exited with code 2.

How do I call this method?


Solution

  • According to the documentation the method invocation has the following syntax:

            obj : <m : t_1 -> ... -> t_n -> u meth; ..> Js.t
                e_i : t_i               (1 <= i <= n)
            -------------------------------------------------
                      obj##m(e_1, ..., e_n) : u
    

    That means, to me, that methods should be called in uncurryied form, i.e.,

    Dom_html.window##scroll(100, 100)