From e0ad7bfeac91fbac6694d677b10c7501167b9caa Mon Sep 17 00:00:00 2001 From: Michael <5672750+mibac138@users.noreply.github.com> Date: Wed, 27 May 2020 17:34:41 +0200 Subject: [PATCH] Add another example to js_namespace (#2157) --- .../reference/attributes/on-js-imports/js_namespace.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/guide/src/reference/attributes/on-js-imports/js_namespace.md b/guide/src/reference/attributes/on-js-imports/js_namespace.md index 7161b1e5..8873e839 100644 --- a/guide/src/reference/attributes/on-js-imports/js_namespace.md +++ b/guide/src/reference/attributes/on-js-imports/js_namespace.md @@ -11,11 +11,16 @@ name (like a class or function name) it'll be accessed through this namespace. extern "C" { #[wasm_bindgen(js_namespace = console)] fn log(s: &str); + + type Foo; + #[wasm_bindgen(constructor, js_namespace = Bar)] + fn new() -> Foo; } log("hello, console!"); +Foo::new(); ``` -This is an example of how to bind `console.log` in Rust. The `log` function will -be available in the Rust module and will be invoked as `console.log` in +This is an example of how to bind namespaced items in Rust. The `log` and `Foo::new` functions will +be available in the Rust module and will be invoked as `console.log` and `new Bar.Foo` in JavaScript.