You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: manual/bindings.wiki
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
= How to bind a JS library for OCaml
2
2
3
-
==Accessing a JS variable, ex: {{{document}}}:
3
+
==Accessing a JS variable, ex: {{{document}}}:
4
4
Write in .ml:
5
5
6
6
<<code language="ocaml"|
@@ -21,7 +21,7 @@ Be careful the function <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsa
21
21
and the value <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.global>> are not typed.
22
22
Verify the library documentation before writing the type.
23
23
24
-
==Binding a JS function
24
+
==Binding a JS function
25
25
26
26
Example from the Js module:
27
27
<<code language="ocaml"|
@@ -31,7 +31,7 @@ let decodeURI (s : js_string t) : js_string t =
31
31
32
32
Have a look at the <<a_api subproject="js_of_ocaml"|module Js_of_ocaml.Js.Unsafe>> module API.
33
33
34
-
==Using a JS constructor, ex: {{{F}}}:
34
+
==Using a JS constructor, ex: {{{F}}}:
35
35
Write in .ml:
36
36
37
37
<<code language="ocaml"|
@@ -50,7 +50,7 @@ val f_fromString : (js_string t -> ... Js.t) Js.constr
50
50
val f_blah : (#Dom_html.element t -> js_string t -> ... Js.t) Js.constr
51
51
>>
52
52
53
-
==Accessing or modifying a JS property to an element
53
+
==Accessing or modifying a JS property to an element
54
54
55
55
When a property is missing in the OCaml interface of an element (for example
56
56
it has been dynamically added by a library), you can access using unsafe
@@ -70,7 +70,7 @@ Here, {{{v}}} may be a JS value or an OCaml value.
70
70
If you want to do that in type safe manner, just define new types for the
71
71
extended elements, or wrap the unsafe functions inside a getter and setter.
72
72
73
-
== Binding a JS object==
73
+
== Binding a JS object
74
74
75
75
Write in .ml and in .mli:
76
76
@@ -107,7 +107,7 @@ class type my_js_type = object
107
107
end
108
108
>>
109
109
110
-
===Example binding some constants:
110
+
===Example binding some constants:
111
111
112
112
For example if the JS class is used to define three constants {{{thelib.Theclass.VALUEA}}}, {{{thelib.Theclass.VALUEB}}}, {{{thelib.Theclass.VALUEC}}},
113
113
@@ -137,7 +137,7 @@ and in .mli:
137
137
val theclass : theclass t
138
138
>>
139
139
140
-
==Constructing JS objects manually
140
+
==Constructing JS objects manually
141
141
If you want to construct a JS object manually
142
142
(without calling a function or a constructor), you can use
143
143
the <<a_manual chapter="Ppx"|Ppx>> syntax extension.
0 commit comments