Skip to content

Ocaml objects and Javascript objects -- clarify documentation #1439

@Josef-Thorne-A

Description

@Josef-Thorne-A

This section of the documentation has some info about using Js.t objects to represent Javscript objects.

The only way I can actually find to create these is using the special syntax and the Ocaml equivalent with @mel.obj:

let john = {
  "name": "john",
  "age": 99,
};
let t = john##name;

These are, as the documentation suggests typed as an OCaml object wrapped in a Js.t type.

Is there any way to use an actual OCaml object literal and wrap it in a Js.t type? This would allow taking advantage of stuff like classes and inheritance which are not exactly the favorite features of most OCamlers but are good to have in your back pocket when you really need them.

If not, it would be good to clarify the documentation as to what's going on here and how OCaml objects relate to what the above syntax is doing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions