Ok, I understand in JS modules are preferred versus Classes, and that there is a ton of ways to write your modules, and I am having some trouble figuring out which are the accepted best practices for each case…
For example, if i am writing some sort of utilities class, this seems to be a good way to go:
export function a
export function b
export function c
however i already have reached a doubt, use functions or constants? export func a
or export const a = () => {}
?
And when we start to think about other scenarios where you will probably want some kind of “Class” like code, or something that you will need to use some dependency injection an so on and so forth, the questions starts to grow, should i still create my modules like utilities as I just mentioned?
Should i create a function that returns an object like this
export default () => {
function a
function b
return { a, b }
}
?
or should i use a constant like this:
const myModule = {}
myModule.a = () => {}
myModule.b = () => {}
export default myModule
or do i take any other approach i haven’t mentioned? Is there a general standard where i should use one or another based on the type of the module? Or any general best practice?