js_class = "Blah"
js_class
属性可以与 method
属性一起使用,以绑定已在 Rust 端重命名的导入 JavaScript 类的 方法。
# #![allow(unused_variables)] #fn main() { #[wasm_bindgen] extern "C" { // We don't want to import JS strings as `String`, since Rust already has a // `String` type in its prelude, so rename it as `JsString`. #[wasm_bindgen(js_name = String)] type JsString; // This is a method on the JavaScript "String" class, so specify that with // the `js_class` attribute. #[wasm_bindgen(method, js_class = "String", js_name = charAt)] fn char_at(this: &JsString, index: u32) -> JsString; } #}