DEV Community

Sharing Classes between Rust and JavaScript

Sendil Kumar on January 03, 2020

Classes in JavaScript The ECMAScript 6 (ES6) introduced classes into the JavaScript. But classes are just a syntactic sugar over the pro...
Collapse
 
peshoicov profile image
peshoicov

Thanks for the tutorial :)
However, for the second example you missed the two steps with the building process - cargo build ..... and wasm-bindgen ........
(Also - on wasm-bindgen command it complained with my package.json I copied form previous example. So I created a new package.json with only "dependencies" in it, ran the wasm-bindgen command and after that I copied the actual package.json from the previous example. That's how it worked.)
...
But what was most frustrating to me was that I got errors when I tried to compile - it didn't want to load the point.js file. It started working for me when I modified it like this:
#[wasm_bindgen(module = "/point.js")]
Absolute path & adding extension.
(Probably it's because of the wasm-bindgen version - 0.2.58 on my machine.
... I don't know.)
Anyway, thanks for the tutorial once again ... it's very useful ;)

Collapse
 
sendilkumarn profile image
Sendil Kumar

Yeah I think there is a bug in the wasm-bindgen. Currently this should be manually amended in the generated JS file.

Collapse
 
siragi profile image
siragi • Edited

same here:
relative module paths aren't supported yet
this worked:

#[wasm_bindgen(module = "point.js")]

Collapse
 
alexm77 profile image
Alex Mateescu

Finally someone who doesn't just post the add(a, b) example and concludes WASM is easy. Thanks a lot for this three part post.

Collapse
 
sendilkumarn profile image
Sendil Kumar

Thanks Will definitely add some more :)