Skip to content

Commit e0ad7bf

Browse files
authored
Add another example to js_namespace (#2157)
1 parent df809df commit e0ad7bf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

guide/src/reference/attributes/on-js-imports/js_namespace.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ name (like a class or function name) it'll be accessed through this namespace.
1111
extern "C" {
1212
#[wasm_bindgen(js_namespace = console)]
1313
fn log(s: &str);
14+
15+
type Foo;
16+
#[wasm_bindgen(constructor, js_namespace = Bar)]
17+
fn new() -> Foo;
1418
}
1519

1620
log("hello, console!");
21+
Foo::new();
1722
```
1823

19-
This is an example of how to bind `console.log` in Rust. The `log` function will
20-
be available in the Rust module and will be invoked as `console.log` in
24+
This is an example of how to bind namespaced items in Rust. The `log` and `Foo::new` functions will
25+
be available in the Rust module and will be invoked as `console.log` and `new Bar.Foo` in
2126
JavaScript.

0 commit comments

Comments
 (0)