Skip to content

Commit

Permalink
Add section on JavaScript interop for custom types
Browse files Browse the repository at this point in the history
For #200.
  • Loading branch information
nino authored and lpil committed Sep 12, 2023
1 parent c43ced5 commit cbe3fa4
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 cbe3fa4

Please sign in to comment.