Property Access
Static property access
Binding to Getter/Setter using bs.get
, bs.set
.
This attribute helps get and set the property of a JavaScript object.
REtype textarea;
[@bs.set] external set_name: (textarea, string) => unit = "name";
[@bs.get] external get_name: textarea => string = "name";
Dynamic property access
Binding to dynamic property access/set using bs.set_index
, bs.get_index
Input:
REtype t;
[@bs.new] external create: int => t = "Int32Array";
[@bs.get_index] external get: (t, int) => int = "";
[@bs.set_index] external set: (t, int, int) => unit = "";
let i32arr = create(3);
i32arr->set(0, 42);
Js.log(i32arr->get(0));
Output:
JSvar i32arr = new Int32Array(3);
i32arr[0] = 42;
console.log(i32arr[0]);