I've been in a debate on whether exporting an already instantiated class makes sense or not:
class myClass{
constructor(){
console.log("Hello");
}
foo(){
console.log("Do something!");
}
}
const cls = new myClass();
export default cls;
Then we consume it like this:
import myClass from './js/myclass';
myClass.foo();
I think this defeats the purposes of classes. My friend says, that this allows you to "just use it" when you require/import the file; similar to NodeJS path
, fs
, etc... functions.
Therefore, could it be considered a bad practice, or is this perfectly acceptable?