File tree Expand file tree Collapse file tree 1 file changed +9
-18
lines changed Expand file tree Collapse file tree 1 file changed +9
-18
lines changed Original file line number Diff line number Diff line change @@ -6,35 +6,26 @@ summary: "This is the `@send` decorator."
6
6
category : " decorators"
7
7
---
8
8
9
- The ` @send ` decorator is used to call a function on an object.
9
+ The ` @send ` decorator is used to bind to a method on an object.
10
10
11
- For example:
11
+ ### Example
12
12
13
13
<CodeTab labels = { [" ReScript" , " JS Output" ]} >
14
14
15
15
``` res
16
- type element
16
+ type document
17
+ @bs.send external getElementById: (document, string) => Dom.element = "getElementById"
18
+ @bs.val external doc: document = "document"
17
19
18
- @scope("document") @val
19
- external createElement: string => element = "createElement"
20
-
21
- @send
22
- external appendChild: (element, element) => element = "appendChild"
23
-
24
- let div = createElement("div")
25
- let button = createElement("button")
26
-
27
- let _ = appendChild(div, button)
20
+ let el = getElementById(doc, "myId")
28
21
```
29
22
30
23
``` js
31
- var div = document .createElement (" div" );
32
-
33
- var button = document .createElement (" button" );
34
-
35
- div .appendChild (button);
24
+ var el = document .getElementById (" myId" );
36
25
```
37
26
38
27
</CodeTab >
39
28
29
+ ### References
40
30
31
+ * [ Bind to JS Function] ( /docs/manual/latest/bind-to-js-function )
You can’t perform that action at this time.
0 commit comments