Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype inheritance #1737

Closed
wants to merge 1 commit into from
Closed

Conversation

eggyal
Copy link

@eggyal eggyal commented Aug 27, 2019

Prototype implementation for draft RFC. Fixes #210 and fixes #1721.

Enables one to do stuff like this—

#[wasm_bindgen(prototype=web_sys::HtmlElement)]
struct MyCustomElement {}

#[wasm_bindgen]
impl MyCustomElement {
    #[wasm_bindgen(constructor)]
    fn new() -> WasmType<MyCustomElement> {
        instantiate! { MyCustomElement{} }
    }
}

// ...

web_sys::window()
    .unwrap()
    .custom_elements()
    .define("my-custom-element", &js_sys::JsFunction::of::<MyCustomElement>())?;

// ...

See Exporting a struct to JS for detailed information, and the examples prefixed web-components- for use-cases.

crates/backend/src/codegen.rs Outdated Show resolved Hide resolved
@alexcrichton
Copy link
Contributor

I'm going to close this while the RFC makes progress to help clean out PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable exported Rust structs to specify prototypal inheritance Add ability to import and extend JS classes
2 participants