In my wrap.ml
, I have a function as follows:
Js.Unsafe.global##.test := Js.wrap_callback (
fun params ->
print_endline "params##.a:";
print_endline (Js.to_string params##.a);
print_endline "params##.b:";
print_endline (Js.to_string params##.b);
Js.string ((Js.to_string params##.a) ^ (Js.to_string params##.b))
);
As a result, in a JavaScript file, I could call e.g., test({a: "abc", b:"efg"})
.
I would like to know in the OCaml file, is there a way to check if the field b
exists in the object params
, before evaluating Js.to_string params##.b
?
You can see how to do this at the bottom of this page:
For this code:
I see the following on the Javascript console: