Sha256: 77f035b6391b9e44f254a411ba18687c5fa6110e276be73b5ea347701c8dad42

Contents?: true

Size: 1007 Bytes

Versions: 30

Compression:

Stored size: 1007 Bytes

Contents

# `js_name = Blah`

The `js_name` attribute can be used to export a different name in JS than what
something is named in Rust. It can be applied to both exported Rust functions
and types.

For example, this is often used to convert between Rust's snake-cased
identifiers into JavaScript's camel-cased identifiers:

```rust
#[wasm_bindgen(js_name = doTheThing)]
pub fn do_the_thing() -> u32 {
    42
}
```

This can be used in JavaScript as:

```js
import { doTheThing } from './my_module';

const x = doTheThing();
console.log(x);
```

Like imports, `js_name` can also be used to rename types exported to JS:

```rust
#[wasm_bindgen(js_name = Foo)]
pub struct JsFoo {
    // ..
}
```

to be accessed like:

```js
import { Foo } from './my_module';

// ...
```

Note that attaching methods to the JS class `Foo` should be done via the
[`js_class` attribute](js_class.html):

```rust
#[wasm_bindgen(js_name = Foo)]
pub struct JsFoo { /* ... */ }

#[wasm_bindgen(js_class = Foo)]
impl JsFoo {
    // ...
}
```

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-23.0.2 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-22.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-21.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-20.0.2 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-20.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-18.0.3 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-17.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-17.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-16.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-15.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-15.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-14.0.4 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-14.0.3 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-14.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-14.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-13.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-12.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-12.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-11.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md
wasmtime-10.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/reference/attributes/on-rust-exports/js_name.md