| 1 |
# `js_class = Blah` |
| 2 |
|
| 3 |
The `js_class` attribute is used to indicate that all the methods inside an |
| 4 |
`impl` block should be attached to the specified JS class instead of inferring |
| 5 |
it from the self type in the `impl` block. The `js_class` attribute is most |
| 6 |
frequently paired with [the `js_name` attribute](js_name.html) on structs: |
| 7 |
|
| 8 |
```rust |
| 9 |
#[wasm_bindgen(js_name = Foo)] |
| 10 |
pub struct JsFoo { /* ... */ } |
| 11 |
|
| 12 |
#[wasm_bindgen(js_class = Foo)] |
| 13 |
impl JsFoo { |
| 14 |
#[wasm_bindgen(constructor)] |
| 15 |
pub fn new() -> JsFoo { /* ... */ } |
| 16 |
|
| 17 |
pub fn foo(&self) { /* ... */ } |
| 18 |
} |
| 19 |
``` |
| 20 |
|
| 21 |
which is accessed like: |
| 22 |
|
| 23 |
```rust |
| 24 |
import { Foo } from './my_module'; |
| 25 |
|
| 26 |
const x = new Foo(); |
| 27 |
x.foo(); |
| 28 |
``` |