Bind to JS Object
As a "record" or "struct" in other languages (like ReScript and C).
As a hash map.
As a class.
As a module to import/export.
ReScript cleanly separates the binding methods for JS object based on these 4 use-cases. This page documents the first three. Binding to JS module objects is described in the Import from/Export to JS section.
Alternatively, you can use ReScript object to model a JS object too:
Alternatively, you can use
set to bind to individual fields of a JS object:
You can also use
set_index to access a dynamic property or an index:
might or might not add/remove keys
contains only values that are of the same type
Then it's not really an object, it's a hash map. Use Js.Dict, which contains operations like
new to emulate e.g.
You can chain
module if the JS module you're importing is itself a class: