| 1 |
# `method` |
| 2 |
|
| 3 |
The `method` attribute allows you to describe methods of imported JavaScript |
| 4 |
objects. It is applied on a function that has `this` as its first parameter, |
| 5 |
which is a shared reference to an imported JavaScript type. |
| 6 |
|
| 7 |
```rust |
| 8 |
#[wasm_bindgen] |
| 9 |
extern "C" { |
| 10 |
type Set; |
| 11 |
|
| 12 |
#[wasm_bindgen(method)] |
| 13 |
fn has(this: &Set, element: &JsValue) -> bool; |
| 14 |
} |
| 15 |
``` |
| 16 |
|
| 17 |
This generates a `has` method on `Set` in Rust, which invokes the |
| 18 |
`Set.prototype.has` method in JavaScript. |
| 19 |
|
| 20 |
```rust |
| 21 |
let set: Set = ...; |
| 22 |
let elem: JsValue = ...; |
| 23 |
if set.has(&elem) { |
| 24 |
... |
| 25 |
} |
| 26 |
``` |