Debian Codegraph @

.cargo/vendor/wasm-bindgen/guide/src/reference/attributes/on-js-imports/constructor.md

raw
1 # `constructor`
2
3 The `constructor` attribute is used to indicate that the function being bound
4 should actually translate to calling the `new` operator in JavaScript. The final
5 argument must be a type that's imported from JavaScript, and it's what will get
6 used in the generated glue:
7
8 ```rust
9 #[wasm_bindgen]
10 extern "C" {
11 type Shoes;
12
13 #[wasm_bindgen(constructor)]
14 fn new() -> Shoes;
15 }
16 ```
17
18 This will attach a `new` static method to the `Shoes` type, and in JavaScript
19 when this method is called, it will be equivalent to `new Shoes()`.
20
21 ```rust
22 // Become a cobbler; construct `new Shoes()`
23 let shoes = Shoes::new();
24 ```