Skip to content

Commit

Permalink
Add a note about renaming types and js_class
Browse files Browse the repository at this point in the history
When a type is renamed in Rust via `js_name` then all method imports
will also need a `js_class` annotation to hook them up correctly.
  • Loading branch information
alexcrichton committed Nov 5, 2018
1 parent 3c31a32 commit 9478a65
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions guide/src/reference/attributes/on-js-imports/js_name.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ extern {

All of these functions will call `console.log` in JavaScript, but each
identifier will have only one signature in Rust.

Note that if you use `js_name` when importing a type you'll also need to use the
[`js_class` attribute][jsclass] when defining methods on the type:

```rust
#[wasm_bindgen]
extern {
#[wasm_bindgen(js_name = String)]
type JsString;
#[wasm_bindgen(method, getter, js_class = "String")]
pub fn length(this: &JsString) -> u32;
}
```

[jsclass]: js_class.html

0 comments on commit 9478a65

Please sign in to comment.