跳过
当附加到 `pub` 结构体字段时,这表示该字段不会暴露给 JavaScript,并且不会在 ES6 类中生成 getter 或 setter。
# #![allow(unused_variables)] #fn main() { use wasm_bindgen::prelude::*; #[wasm_bindgen] pub struct Foo { pub bar: u32, #[wasm_bindgen(skip)] pub baz: u32, } #[wasm_bindgen] impl Foo { pub fn new() -> Self { Foo { bar: 1, baz: 2 } } } #}
这里 `bar` 字段将可从 JS 读取和写入,但 `baz` 字段在 JS 中将为 `undefined`。
import('./pkg/').then(rust => {
let foo = rust.Foo.new();
// bar is accessible by getter
console.log(foo.bar);
// field marked with `skip` is undefined
console.log(foo.baz);
// you can shadow it
foo.baz = 45;
// so accessing by getter will return `45`
// but it won't affect real value in rust memory
console.log(foo.baz);
});