Skip to content

Commit

Permalink
Add section on JavaScript interop for custom types
Browse files Browse the repository at this point in the history
  • Loading branch information
nino committed Sep 9, 2023
1 parent 0044577 commit 9438f50
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions book-src/tour/custom-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,23 @@ LoggedIn("Kim")
guest,
{logged_in, <<"Kim">>}.
```

## JavaScript interop

When compiling to JavaScript, each constructor becomes a class of the same name.
Each of the generated JavaScript classes has a constructor with the same
arguments as the original type constructor.

```gleam
// Gleam
Guest
LoggedIn("Kim")
Cat(name: "Jinx", cuteness: 2002)
```

```javascript
// JavaScript
new Guest(); // => {}
new LoggedIn("Kim"); // => { 0: "Kim" }
new Animal("Jinx", 2002); // => { name: "Jinx", cuteness: 2002 }
```

0 comments on commit 9438f50

Please sign in to comment.