guide: add exhuastive reference docs for #[wasm_bindgen] attributes

This commit is contained in:
Nick Fitzgerald
2018-08-06 16:35:28 -07:00
parent b6a6dee7f1
commit 33520d4828
19 changed files with 477 additions and 280 deletions

View File

@ -0,0 +1,26 @@
# `method`
The `method` attribute allows you to describe methods of imported JavaScript
objects. It is applied on a function that has `this` as its first parameter,
which is a shared reference to an imported JavaScript type.
```rust
#[wasm_bindgen]
extern {
type Set;
#[wasm_bindgen(method)]
fn has(this: &Set, element: &JsValue) -> bool;
}
```
This generates a `has` method on `Set` in Rust, which invokes the
`Set.prototype.has` method in JavaScript.
```rust
let set: Set = ...;
let elem: JsValue = ...;
if set.has(&elem) {
...
}
```