This is the unpublished documentation of wasm-bindgen, the published documentation is available on the main Rust and WebAssembly documentation site . Features documented here may not be available in released versions of wasm-bindgen.


When attached to a Rust "constructor" it will make the generated JavaScript bindings callable as new Foo().

For example, consider this exported Rust type and constructor annotation:

# #![allow(unused_variables)]
#fn main() {
pub struct Foo {
    contents: u32,

impl Foo {
    pub fn new() -> Foo {
        Foo { contents: 0 }

    pub fn get_contents(&self) -> u32 {

This can be used in JavaScript as:

import { Foo } from './my_module';

const f = new Foo();