'How to use exported struct in JS file?

I have the following definitions in the Rust code:

#[wasm_bindgen]
pub struct Point {
    x: i32,
    y: i32,
}

#[wasm_bindgen]
impl Point {
    #[wasm_bindgen(constructor)]
    pub fn new(x: i32, y: i32) -> Point {
        Point { x, y }
    }
}

I logged the created object in JS file:

let p = new Point(23, 34);
console.log(p);

But it's giving me a pointer value with the prototype, I don't know how to use it.

enter image description here

How can I get a JS object like { x: 23, y: 34 } with the prototype?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source