I've been reading about ES6 modules and have noticed that classes are either exported as-is, or after being new
ed up.
For instance:
class Class1 extends SomeOtherClass {
constructor() {
super();
}
//Class1 methods and data here
}
export default new Class1();
..while in Class2.js:
class Class2 extends YetAnotherClass {
constructor() {
super();
}
//Class2 methods and data here
}
export default Class2;
Fair to assume that in the case of Class1 you've created a singleton, while with Class2 after importing it you can new up independent instances of it at will? If so, are there other scenarios for using new
when exporting a class vs not?