I currently develop a project based on node.js with Babel.
I have a userService.js file that is supposed to be a singleton and manage everything I want with the user and also keep the user's state.
Why would I write this module in this way:
class UserService { //methods //properties}
export default new UserService(); //so it is a singleton
and import it this way:
import userService from 'userService';
and not this way:
export function login() {} //other functions etc
export var user={}
and import it like:
import * as userService from 'userService
';
is it only a stylistic difference?
I get that for example importing only the login without the logout method doesn't make sense so exporting a class with all the methods sounds good but the other way has the advantage of not having to use "this" keyword all the time.