js_class = Blah

js_class 屬性用於指示 impl 區塊內的所有方法都應該附加到指定的 JS 類別,而不是從 impl 區塊中的 self 類型推斷。 js_class 屬性最常與結構上的 js_name 屬性 配對使用

#![allow(unused)]
fn main() {
#[wasm_bindgen(js_name = Foo)]
pub struct JsFoo { /* ... */ }

#[wasm_bindgen(js_class = Foo)]
impl JsFoo {
    #[wasm_bindgen(constructor)]
    pub fn new() -> JsFoo { /* ... */ }

    pub fn foo(&self) { /* ... */ }
}
}

其存取方式如下

#![allow(unused)]
fn main() {
import { Foo } from './my_module';

const x = new Foo();
x.foo();
}