JavaScript names corresponding to bound components can always be specified explicitly (with the use of attributes). When the naming is left implicit, a JavaScript name is automatically derived from the OCaml name by applying the following rules:
-
uppercasing every character following an underscore;
-
removing every underscore;
-
uppercasing the first character when generating object constructor names.
This automatic naming convention can be partially disabled by adding
an attribute [@js.verbatim_names] on outer structures. When the attribute
[@js.verbatim_names] is inherited from the context, the rule 1 and 2 are
disabled.
For instance,
type myType = { x_coord : int; y_coord : int [@js "Y"]}is mapped to a JS record with two fields named "xCoord" and "Y" whereas
type myType = { x_coord : int; y_coord : int [@js "Y"]} [@@js.verbatim_names]is mapped to a JS record with two fields named "x_coord" and "y".