Skip to content

Latest commit

 

History

History
43 lines (29 loc) · 702 Bytes

bs.send.md

File metadata and controls

43 lines (29 loc) · 702 Bytes

[@bs.send]

bs.send is used to call a function inside an object.

JS example:

element.appendChild(anotherElement);

You type and use it like so:

fn(obj, arg1, arg2, arg3, ...)

and BS compiles it to:

obj.fn(arg1, arg2, arg3, ...)

For example:

type element;
[@bs.scope "document"] [@bs.val] external createElement: string => element = "";
[@bs.send] external appendChild: (element, element) => element = "";

let div = createElement("div");
let button = createElement("button");

appendChild(div, button)

compiles to:

var div = document.createElement("div");
var button = document.createElement("button");

div.appendChild(button);