How would one rewrite this class to a plain object?
class ExampleClass {
firstPropery: number = 0;
secondProperty!: string;
async exampleMethod(): Promise<void> {
const { secondProperty } = await SomeHelperClass.exampleRequest();
this.secondProperty = secondProperty;
}
}
I would think it's something similar as this
interface IExample {
firstProperty: number;
secondProperty: string;
exampleMethod: () => Promise<void>;
}
const Example: IExample = {
firstProperty: 0,
exampleMethod: async (): Promise<void> => {
const { secondProperty } = await SomeHelperClass.exampleRequest();
...
}
}
But how to set the secondProperty
via the exampleMethod
? In the class method I can just write this.secondProperty = ...
, which I cannot do in the plain object.
My second question is, with the class I would make a new object like this const newObject = new ExampleClass();
. With the plain object way, how would I make a new object instance?
Any help is gladly appreciated!