Skip to content

Commit da0c13c

Browse files
Improve documentation
Co-Authored-By: Michael Schmidt <[email protected]>
1 parent 9fc08b8 commit da0c13c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

guide/src/reference/static-js-objects.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ extern "C" {
7070
}
7171
```
7272

73-
## Undeclared
73+
## Optional statics
7474

75-
When accessing an in JS undeclared value, it will throw in JS. This can be accounted for by using `Option`.
75+
If you expect the JavaScript value you're trying to access to not always be
76+
available you can use `Option<T>` to handle this:
7677

7778
```rust
7879
extern "C" {
@@ -82,7 +83,9 @@ extern "C" {
8283
}
8384
```
8485

85-
If `crypto` is undeclared in JS, it will simply return `None` in Rust.
86+
If `crypto` is not declared or nullish (`null` or `undefined`) in JavaScript,
87+
it will simply return `None` in Rust. This will also account for namespaces: it
88+
will return `Some(T)` only if all parts are declared and not nullish.
8689

8790
## Static strings
8891

0 commit comments

Comments
 (0)