How do you export a class from a web module?

Hi Simon,

I had a go at exporting a class module to the front-end but was not able to. I’ll investigate further to see if there’s a solution.

However, as a workaround instead of trying to create and export a class you can try modifying your backend code and create a factory function instead and export it that way.

I created a simple example for demonstration:

backend/constructor.jsw

export function createPerson(name, age) {
 return {name, age};
}

client-side code

import { createPerson } from 'backend/constructor.jsw';

$w.onReady(function () {
 let john = createPerson('John', 27)
   .then((person) => {
    console.log(person);
    });
});

returns an Object

I also found these helpful links you may want to check out.

I hope this helps out!

Best regards,
Miguel