Implement a js_name customization

This'll allow binding multiple signatures of a JS function as well as otherwise
changing the name of the JS function you're calling from the Rust function that
you're defining.

Closes #72
This commit is contained in:
Alex Crichton
2018-03-22 19:05:14 -07:00
parent a8045fbbe9
commit 7ebc428646
10 changed files with 155 additions and 66 deletions

View File

@ -24,10 +24,10 @@ extern {
fn body(this: &HTMLDocument) -> Element;
type Element;
#[wasm_bindgen(method, setter = "innerHTML")]
#[wasm_bindgen(method, setter = innerHTML)]
fn set_inner_html(this: &Element, html: &str);
#[wasm_bindgen(method)]
fn appendChild(this: &Element, other: Element);
#[wasm_bindgen(method, js_name = appendChild)]
fn append_child(this: &Element, other: Element);
}
// Called by our JS entry point to run the example
@ -35,5 +35,5 @@ extern {
pub fn run() {
let val = document.createElement("p");
val.set_inner_html("Hello from Rust!");
document.body().appendChild(val);
document.body().append_child(val);
}