| 1 |
# `skip` |
| 2 |
|
| 3 |
When attached to a `pub` struct field this indicates that field will not be exposed to JavaScript, |
| 4 |
and neither getter nor setter will be generated in ES6 class. |
| 5 |
|
| 6 |
```rust |
| 7 |
use wasm_bindgen::prelude::*; |
| 8 |
|
| 9 |
#[wasm_bindgen] |
| 10 |
pub struct Foo { |
| 11 |
pub bar: u32, |
| 12 |
|
| 13 |
#[wasm_bindgen(skip)] |
| 14 |
pub baz: u32, |
| 15 |
} |
| 16 |
|
| 17 |
#[wasm_bindgen] |
| 18 |
impl Foo { |
| 19 |
pub fn new() -> Self { |
| 20 |
Foo { |
| 21 |
bar: 1, |
| 22 |
baz: 2 |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
``` |
| 27 |
|
| 28 |
Here the `bar` field will be both readable and writable from JS, but the |
| 29 |
`baz` field will be `undefined` in JS. |
| 30 |
|
| 31 |
```js |
| 32 |
import('./pkg/').then(rust => { |
| 33 |
let foo = rust.Foo.new(); |
| 34 |
|
| 35 |
// bar is accessible by getter |
| 36 |
console.log(foo.bar); |
| 37 |
// field marked with `skip` is undefined |
| 38 |
console.log(foo.baz); |
| 39 |
|
| 40 |
// you can shadow it |
| 41 |
foo.baz = 45; |
| 42 |
// so accessing by getter will return `45` |
| 43 |
// but it won't affect real value in rust memory |
| 44 |
console.log(foo.baz); |
| 45 |
}); |
| 46 |
``` |