File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ id : " ref-value-assignment"
3
+ keywords : ["ref", "assign"]
4
+ name : " :="
5
+ summary : " This is the `ref value assignment` operator."
6
+ category : " operators"
7
+ ---
8
+
9
+ This operator assigns a new value to a ` ref ` .
10
+
11
+ <CodeTab labels = { [" ReScript" , " JS Output" ]} >
12
+
13
+ ``` res
14
+ let total = ref(0)
15
+ total := 1
16
+ ```
17
+
18
+ ``` js
19
+ var total = {
20
+ contents: 0
21
+ };
22
+
23
+ total .contents = 1 ;
24
+ ```
25
+
26
+ </CodeTab >
27
+
28
+ A ` ref ` is a builtin record type with a ` mutable contents ` field. Therefore the ` := ` operator is just a shorthand version for the following code:
29
+
30
+ <CodeTab labels = { [" ReScript" , " JS Output" ]} >
31
+
32
+ ``` res
33
+ let total = ref(0)
34
+ total.contents = 1
35
+ ```
36
+
37
+ ``` js
38
+ var total = {
39
+ contents: 0
40
+ };
41
+
42
+ total .contents = 1 ;
43
+ ```
44
+
45
+ </CodeTab >
You can’t perform that action at this time.
0 commit comments